Forum Discussion
Identifying the 2 most recent days in Power Query
- 6 years ago
Hello Anonymous
check out this solution. It involves of creating a list of the 2 latest dates in a date-column. This list is then used to filter the whole table
let Source = #table ( {"Date","Column1"}, { {"43466","test1"}, {"43678","test2"}, {"43554","test3"}, {"43819","test4"}, {"43831","test5"}, {"43833","test6"}, {"43838","test7"}, {"43851","test8"}, {"43851","test9"}, {"43848","test10"} } ), ToDate = Table.TransformColumns ( Source, { { "Date", each Date.From(Number.From(_)), type date } } ), GetListToFilter = List.FirstN ( List.Sort ( List.Distinct ( ToDate[Date] ), Order.Descending ), 2 ), SelectRows = Table.SelectRows ( ToDate, (row)=> List.Contains ( GetListToFilter, row[Date] ) ) in SelectRowsCopy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query, or I could create a custom function what makes it easier to apply if you are not used that much to power query.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hey Anonymous
You can use the TODAY() Function in DAX: https://docs.microsoft.com/en-us/dax/today-function-dax
So you can just use the Date = TODAY()
And the Date.AddDays(TODAY(),-2)
That way it will be dynamic relative to "today"
- edhans6 years agoCommunity Champion
TODAY() though doesn't work in Power Query, which is what I thought this was about. You'd need to start with DateTime.LocalNow() for today's date and time, but still not clear on the requirements.
- Anonymous6 years agoNot applicable
I am tyring to do this in power query
I don't know if the current data time function because there is never data in there for the current day. I also cannot just pick the day before the max value because the next most recent day might be from 3 days prior to that
- Jimmy8016 years agoCommunity ChampionHey
Check out my solution then
Jimmy
- Anonymous6 years agoNot applicable
edhans Yeah my bad. Forgot it was in Power Query. You are correct, but it looks like his last two days of data may also be dynamic and I have no clue how to do last two USED days. Would require a few IFs to find last non-blank day.