Forum Discussion
SQL Statement to limit Data import
- Anonymous3 years ago
Hi kaye123 ,
I don't know what you are using the query language, so I will write an example in MSSQL for you to get the last 5 years. I recommend that you get the data by filtering it on the sql side.
select * from table_name where FY>=YEAR(GETDATE())-5
but if you want to get all the data then you have to add the following step to the data having the Power Query side
= Table.SelectRows(#"Changed Type", each [FY] >= Date.Year(DateTime.LocalNow())-5)
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best regards 🙂
Thanks everyone for the input. I have now used below SQL as my final code. Note FiscalYear is not a date but just a 4 digit year number. so I added a VARCHAR.
SELECT Column1, Column2, Column3
FROM DATAAll
WHERE FiscalYear >= CAST(YEAR(GETDATE()) - 5 AS VARCHAR(4))