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.
I have a table like the one below
region industry year value
North America farming 2019 400
Europe carpentry 2020 600
North America farming 2020 700
Europe capentry 2021 800
North America farming 2021 400
In dax
Solved! Go to Solution.
Hi @jo123456
You can put the following code to advanced editor in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ssvKslQ0lFyzE0tykxOVEhLLMrNzEsHihgZGFoCKRMDA6VYnWgl19Ki/IJUoEByYlFBal5JUSVYjZEBkDKDqsFnGFihOQHDDIGUBTGGGcJcFgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [region = _t, industry = _t, year = _t, value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"region", type text}, {"industry", type text}, {"year", Int64.Type}, {"value", Int64.Type}}),
Custom1 = Table.AddColumn(#"Changed Type","Custom",each Table.SelectRows (#"Changed Type",(x) =>x [region]=[region] and x[industry]=[industry] and x[year]=[year]-1)),
#"Expanded Custom" = Table.ExpandTableColumn(Custom1, "Custom", {"value"}, {"value.1"}),
#"Added Custom" = Table.AddColumn(#"Expanded Custom", "FYQ1", each [value.1]*0.25),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"value.1"}),
#"Sorted Rows" = Table.Sort(#"Removed Columns",{{"region", Order.Ascending}})
in
#"Sorted Rows"
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @jo123456
You can put the following code to advanced editor in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ssvKslQ0lFyzE0tykxOVEhLLMrNzEsHihgZGFoCKRMDA6VYnWgl19Ki/IJUoEByYlFBal5JUSVYjZEBkDKDqsFnGFihOQHDDIGUBTGGGcJcFgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [region = _t, industry = _t, year = _t, value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"region", type text}, {"industry", type text}, {"year", Int64.Type}, {"value", Int64.Type}}),
Custom1 = Table.AddColumn(#"Changed Type","Custom",each Table.SelectRows (#"Changed Type",(x) =>x [region]=[region] and x[industry]=[industry] and x[year]=[year]-1)),
#"Expanded Custom" = Table.ExpandTableColumn(Custom1, "Custom", {"value"}, {"value.1"}),
#"Added Custom" = Table.AddColumn(#"Expanded Custom", "FYQ1", each [value.1]*0.25),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"value.1"}),
#"Sorted Rows" = Table.Sort(#"Removed Columns",{{"region", Order.Ascending}})
in
#"Sorted Rows"
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
note my current one is in dax
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
7 | |
7 | |
6 | |
6 |