Forum Discussion
Matrix based upon different categories in columns
Hello everyone,
I would like to make a matrix based upon type transport and fuel. The amounts are in different columns.
The rows should show the transporttypes and fuel
| Table | |||||
| Date | Type transport | Amount | Fuel | Amount Diesel | Total |
| 1-10-2022 | Overnight | 100,00 | Diesel | 14,00 | 114,00 |
| 1-10-2022 | International | 1.000,00 | Diesel | 140,00 | 1.140,00 |
| 1.254,00 | |||||
| Matrix | |||||
| Overnight | 100,00 | 100,00 | |||
| International | 1.000,00 | 1.000,00 | |||
| Fuel | 154,00 | 154,00 | |||
| 1.254,00 |
Hi, JeroenP ;
You need change the data in power query ,
1.Unpivot Fuel\Amount Diesel columns
2.add conditional columns.
3.remove other columns:
4.group by it
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ1NNA1MjAyUtJR8i9LLcrLTM8oAbINDQx0DAyADJfM1OLUHJCICUTAEMKI1UHV7JlXAtSdWJKZn5cIVg5UhGkEVMRQD8qMjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Type transport" = _t, Amount = _t, Fuel = _t, #"Amount Diesel" = _t, Total = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Type transport", type text}, {"Amount", Int64.Type}, {"Fuel", type text}, {"Amount Diesel", Int64.Type}, {"Total", type text}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Total"}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Date", "Type transport", "Amount"}, "Attribute", "Value"), #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Columns", "Amount1", each if [Attribute] = "Fuel" then [Amount] else [Value]), #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Type", each if [Attribute] = "Fuel" then [Type transport] else "Fuel"), #"Removed Columns1" = Table.RemoveColumns(#"Added Conditional Column1",{"Type transport", "Amount", "Attribute", "Value"}), #"Grouped Rows" = Table.Group(#"Removed Columns1", {"Date", "Type"}, {{"Amount", each List.Sum([Amount1]), type number}}) in #"Grouped Rows"the final show:
then in desktop could add matrix.
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- v-yalanwu-msftCommunity Support
Hi, JeroenP ;
You need change the data in power query ,
1.Unpivot Fuel\Amount Diesel columns
2.add conditional columns.
3.remove other columns:
4.group by it
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ1NNA1MjAyUtJR8i9LLcrLTM8oAbINDQx0DAyADJfM1OLUHJCICUTAEMKI1UHV7JlXAtSdWJKZn5cIVg5UhGkEVMRQD8qMjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Type transport" = _t, Amount = _t, Fuel = _t, #"Amount Diesel" = _t, Total = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Type transport", type text}, {"Amount", Int64.Type}, {"Fuel", type text}, {"Amount Diesel", Int64.Type}, {"Total", type text}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Total"}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Date", "Type transport", "Amount"}, "Attribute", "Value"), #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Columns", "Amount1", each if [Attribute] = "Fuel" then [Amount] else [Value]), #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Type", each if [Attribute] = "Fuel" then [Type transport] else "Fuel"), #"Removed Columns1" = Table.RemoveColumns(#"Added Conditional Column1",{"Type transport", "Amount", "Attribute", "Value"}), #"Grouped Rows" = Table.Group(#"Removed Columns1", {"Date", "Type"}, {{"Amount", each List.Sum([Amount1]), type number}}) in #"Grouped Rows"the final show:
then in desktop could add matrix.
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.