Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Does anybody know how to convert the following code from DAX to Power Query? I'm not sure what the equivalent function for Calculate and Offset is in M Query. There's an example of what the table should look like at the bottom of the image.
Solved! Go to Solution.
Does it need to work with the year column or is it acceptable to add an index column? Remember that in Power Query you can address any row via {x} where x can be a row number or a condition.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtFTSUTI2NQUyTPTMzZRidUCiRgZAUXMzSwtjUz0LA6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, #"Sales Amount" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Sales Amount", Currency.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Prev Year Sales", (k)=> try #"Changed Type"{[Year = k[Year]-1]}[Sales Amount] otherwise null,Currency.Type)
in
#"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
Does it need to work with the year column or is it acceptable to add an index column? Remember that in Power Query you can address any row via {x} where x can be a row number or a condition.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtFTSUTI2NQUyTPTMzZRidUCiRgZAUXMzSwtjUz0LA6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, #"Sales Amount" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Sales Amount", Currency.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Prev Year Sales", (k)=> try #"Changed Type"{[Year = k[Year]-1]}[Sales Amount] otherwise null,Currency.Type)
in
#"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 17 | |
| 9 | |
| 9 | |
| 7 | |
| 7 |