Forum Discussion

JeroenP's avatar
JeroenP
Frequent Visitor
3 years ago
Solved

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     
DateType transportAmountFuelAmount DieselTotal
1-10-2022Overnight100,00Diesel14,00114,00
1-10-2022International1.000,00Diesel140,001.140,00
      
     1.254,00
Matrix     
Overnight100,00   100,00
International1.000,00   1.000,00
Fuel154,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-msft's avatar
    v-yalanwu-msft
    Community 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.