Forum Discussion
Anonymous
3 years agoNot applicable
Using column header as values for calculation
Hi Experts, I have a table as below in my Power BI: 2022 2023 2024 Next_Order_Year 0 1 2 2025 0 1 ...
bolfri
3 years agoSolution Sage
Hi, I think you should consider unpivoting your data.
Step 1. Unpivot your data
Simply select Next_Order_Year (and other columns if you have) and from Ribbon > Transform > Unpivot Columns > Unpivot Other Columns
= Table.UnpivotOtherColumns(Source, {"Next_Order_Year"}, "Year", "Value")
Step 2. Add condition for Next_Order_Year
= Table.AddColumn(#"Unpivoted Other Columns", "IsYearOK", each [Year] < [Next_Order_Year])
Step 3. Keep only rows with IsYearOK = True or you can leave it here (if you need that data) and filter it with a measure or on the visual
Power Query M:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTIEYiMQNjAyVYrVQQgaQARNwIJGUAFDiKCxUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"2022" = _t, #"2023" = _t, #"2024" = _t, Next_Order_Year = _t]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Next_Order_Year"}, "Year", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "IsYearOK", each [Year] < [Next_Order_Year]),
#"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Next_Order_Year", Int64.Type}, {"Year", Int64.Type}, {"Value", Int64.Type}, {"IsYearOK", type logical}})
in
#"Changed Type"