Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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!
User | Count |
---|---|
11 | |
8 | |
5 | |
5 | |
4 |
User | Count |
---|---|
16 | |
14 | |
8 | |
6 | |
6 |