Aahi
Aahi

Reputation: 19

Bigquery SQL - Exclude rows/data for current Financial Year

I have a query in which I want to add a WHERE clause to exclude data for current Financial Year (without hardcoding it) Note: FinancialYear 1st July to 30 June

SELECT * from TABLE A
WHERE FinancialYear != Current_Financial_Year

Based on a date column I have extracted Financial Year as below but not sure how to check if its current financial year and then exclude it using the WHERE clause above

extract(year from date_add(CalendarDate, interval 6 month)) as FinancialYear

Upvotes: 0

Views: 332

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269973

You can compare to the current financial year by using similar logic on current_date:

where extract(year from date_add(CalendarDate, interval 6 month)) <>
      extract(year from date_add(Current_Date, interval 6 month))

Upvotes: 1

The best approach would be to use the following query

select * from Table_A where FinancialYear NOT LIKE '%2021%'

All you need to change is the year and you will get the respective data :) Regards :)

Upvotes: 1

Related Questions