Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi, I have a table similar to below.
| Region | Month of Period End | Attribute | Value |
| State A | 4/1/2022 | Homes Sold | 24% |
| State A | 3/1/2022 | Homes Sold | 22% |
| State A | 2/1/2022 | Homes Sold | 5% |
| State A | 1/1/2022 | Homes Sold | 6% |
| State B | 5/1/2022 | Home Price | 8% |
| State B | 4/1/2022 | Home Price | 9% |
| State B | 3/1/2022 | Home Price | 2% |
| State B | 2/1/2022 | Home Price | 34% |
| State B | 1/1/2022 | Home Price | 22% |
I want to create a dynamic column of lagged values such that the period of lag (1 month/2 months/3 months/...) can be selected via a slicer. The calculation of the lag column depicted in the last 3 columns below:
| Region | Month of Period End | Attribute | Value | Lagged by 1 (Minus 1 month) | Lagged by 2 (Minus 2 months) | Lagged by 3 (Minus 3 months) |
| State A | 4/1/2022 | Homes Sold | 24% | 22% | 5% | .. |
| State A | 3/1/2022 | Homes Sold | 22% | 5% | 6% | .. |
| State A | 2/1/2022 | Homes Sold | 5% | 6% | - | .. |
| State A | 1/1/2022 | Homes Sold | 6% | - | - | .. |
| State B | 5/1/2022 | Home Price | 8% | 9% | 2% | .. |
| State B | 4/1/2022 | Home Price | 9% | 2% | 34% | .. |
| State B | 3/1/2022 | Home Price | 2% | 34% | 22% | .. |
| State B | 2/1/2022 | Home Price | 34% | 22% | - | .. |
| State B | 1/1/2022 | Home Price | 22% | - | - | .. |
Please help me out with what will work. I want to input these columns using M in the power query. Thanks.
Solved! Go to Solution.
Hi @Anonymous,
I think doing this in PQ would be a bit of overkill, why would you need this chunks of duplicated data to be stored?
Then, how do you want to make it slicer dependant? Via slicer parameter?
I love PQ/M and, probably, a bit sceptical re DAX, but in this case, it looks like a DAX job.
Assuming your table is called Data and you have another table called Offset, which is just one column of 1,2,3,4,5:
which you use as the slicer:
This is the DAX for calculating a measure (which you can add as a column to your visual):
Lagged =
var dt = FIRSTDATE(DATEADD('Data'[Month of Period End], -minx('Offset', 'Offset'[Offset]), MONTH))
return CALCULATE(SUM('Data'[Value]), Filter(ALL('Data'[Month of Period End]), 'Data'[Month of Period End] = dt))
Cheers,
John
Hi @Anonymous,
I think doing this in PQ would be a bit of overkill, why would you need this chunks of duplicated data to be stored?
Then, how do you want to make it slicer dependant? Via slicer parameter?
I love PQ/M and, probably, a bit sceptical re DAX, but in this case, it looks like a DAX job.
Assuming your table is called Data and you have another table called Offset, which is just one column of 1,2,3,4,5:
which you use as the slicer:
This is the DAX for calculating a measure (which you can add as a column to your visual):
Lagged =
var dt = FIRSTDATE(DATEADD('Data'[Month of Period End], -minx('Offset', 'Offset'[Offset]), MONTH))
return CALCULATE(SUM('Data'[Value]), Filter(ALL('Data'[Month of Period End]), 'Data'[Month of Period End] = dt))
Cheers,
John
This was awesome, thanks!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 8 | |
| 5 | |
| 5 |