Forum Discussion
Max Date Math Issues In Power Query
- 5 years ago
Hi asjones,
Since you need 2 columns based on the max date,I would suggest you first create a column to get the max date,using below M codes:
=Table.Max(#"Changed Type","Date")Then create another 2 columns to get 7days and 14days:
=if [Date]>Date.AddDays([Max date.Date],-7) then "7 days" else null=if [Date]>Date.AddDays([Max date.Date],-14) then "14 days" else nullAnd you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my reply as a solution!
Here's a way that'll work nice and fast. Let's say your current final step is named LastStep. Just add a new step named MaxDate7. Then in the Formula Bar, type:
= Date.AddDays(List.Max(List.Buffer(LastStep[Dates])),-7)
Then add your column; add a new step named "NewColumn", then in the formula bar, type:
= Table.AddColumn(LastStep, "DateCompare", each if [Date] > MaxDate7 then "7 Days" else "-", type text)
This way your Max Date-7 days is computed once and stored as a variable. Having it in the in statement will cause you trouble. If you want to add the Date-14 variable, just add another step before you add your columns named MaxDate14, and that would be:
= Date.AddDays(MaxDate7, -7)
--Nate
Just be careful with List.Buffer on a large list. Put a few hundred thousand or million records in it, and it could cause Power Query to consume all RAM on the PC. I thought about doing it that way, but I still contend Power Query isn't the right place for this unless you know it is going to be a relatively small dataset.