Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Solved! Go to Solution.
Add a column:
= Table.AddColumn(TableName, "LastYearDate", each Date.AddYears([DateColumn, -1))
If I named that step LastYear, then I would add a join:
Table.Join(TableName, {"LastYearDate"}, LastStep, {"LastYearDate"}, JoinKind.LeftOuter)
Now your Current Dates are lined up with last years dates, along with everything from those rows.
--Nate
Add a column:
= Table.AddColumn(TableName, "LastYearDate", each Date.AddYears([DateColumn, -1))
If I named that step LastYear, then I would add a join:
Table.Join(TableName, {"LastYearDate"}, LastStep, {"LastYearDate"}, JoinKind.LeftOuter)
Now your Current Dates are lined up with last years dates, along with everything from those rows.
--Nate
It solved for me, thank you.
I'm avoiding to do this in DAX cause I need to dynamically rename the MonthlyValue based on other values and I managed to do this only in power query. Otherwise I wouldd-ve stuck with dax
Hi @refex ,
Did my answer work for you?
If so, please consider marking it as the solution to help others find the answer quicker.
Thanks,
Pete
Proud to be a Datanaut!
Hi @refex ,
Try:
Date.AddYears([Date], -1)
Pete
Proud to be a Datanaut!
Hi @BA_Pete, thank you for your answer.
With your suggestion I can build a date that goes back exaclty one year, but this does not give me the value of the field "MonthlyValue" on that date
@refex ,
Indeed, it doesn't. That's what DAX is for.
Smart-alec responses aside, if you REALLY want to do this in Power Query, then you would do something like this:
1) Aggregate (group) your table by relevant dimensions and date i.e. you would have only a single row for each date/dimension combination, not multiple transactions within each date.
2) Merge all row-unique dimension fields into a single field. This may be [Department], [Client], [Sale Date] etc. so you would end up with a single field that looks something like this:
Sportwear-ABC Co.-05/06/2021
3) You would then do the same again, but use your prior year date field instead.
4) Self-merge the query on itself on [Merged Field Prior Year] LEFT OUTER [Merged Field Current Year]. This should then add the prior year date row for that combination of dimensions onto the 'current' year row. This would apply to any date that had values for that dimension combination on exactly the same date in the year prior.
Hopefully you can see quite quickly that Power Query/M is not the place to be doing things like this. It really is what DAX is entirely designed for/to do.
Pete
Proud to be a Datanaut!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.