Forum Discussion
Sales Table (Need Only Last 4 Years) Help/Question
- 4 years ago
Hi IamTDR,
This should adjust for the 8 months difference between the current date and your fiscal year:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Filtered Rows" = Table.SelectRows(Source, each [fiscal_year] > Date.Year(Date.AddMonths(DateTime.LocalNow(), +8)) - 4) in #"Filtered Rows"
Hi IamTDR,
Would you be able to provide a sample file and/or a screenshot of the formatting that comes in natively, particularly of the fiscal month/fiscaldate field that you are referring to?
- Knighthawk4 years agoHelper I
Hi IamTDR,
Will this work:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Filtered Rows" = Table.SelectRows(Source, each [fiscal_year] > Date.Year(DateTime.LocalNow()) - 4) in #"Filtered Rows"- IamTDR4 years agoResponsive Resident
No. It wont because the field 'fiscal_year' is seen as a number and not a date.
I usually duplicate this table, although I do not enable load, remove other fields except date field, remove duplicates, sort, and then keep first 4 rows. Then I do a InnerJoin between the two tables. This keeps the data being native but the results are rather slow. Before doing this I would manually filter the table but I no longer want to revise this report yearly. Goal is to be dynamic.- Knighthawk4 years agoHelper I
Hi IamTDR,
Since I am still rather new to Power Query, I definitely might be missing something, or there could of course easily be differences between your real data and the test data I am creating for my test code. However, the code I provided seems to be working with [fiscal_year] being set to type number. In case it can help to overcome the issue between comparing number and date though, I added one additional function (Number.From) to convert the "current year - 4" to a type number (in case it was being seen as date and causing the issue you are running into) so that the logic code would be comparing type number to type number. You could add this function around [fiscal_year] also just to be safe if you are still running into a type issue. I hope that this helps. Without seeing the whole picture though, maybe I am missing something.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Filtered Rows" = Table.SelectRows(Source, each [fiscal_year] > Number.From(Date.Year(DateTime.LocalNow())) - 4) in #"Filtered Rows"