Forum Discussion

akarca's avatar
akarca
Frequent Visitor
3 years ago
Solved

Create table from another table

Hello, I have a table below. I would like to sum monthly volume base and create a new table with the horizontal month columns.

 

ProductVolume(kg)Date
A96.01.2022
A1091,9755.02.2022
B14095.01.2022
C10964,162.02.2022
D3032,645.01.2022
B12130,565.01.2022
C12597,126.01.2022
D466,566.03.2022
A1382,46.04.2022
C2822,46.08.2022
A637220.10.2022
D280820.09.2022
A3893,7620.11.2022
B1290,245.11.2022
B1612,85.11.2022

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi akarca ,

    I have created a simple sample, please refer to my pbix fiel to see if it helps you.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY8xDsIwDEXvkgkkS7GdxElGoAdgYqk6IEAMgCqh9v4kLW1DxeDBfnrfdl2r47u99pdOgTq1z/512zzu29RU5+6mGqjVLjUxFSOzJi3zkDASRO8mxtoNbJ+ZxcIZ54fREQski8MDq9LAoGEQu9aGOCaD4ORvJLvogXh9Yo60IoVlyuNNYJh32S/JeRy4IKFwxPhlC2rGeQ8HDBOJE8iKCdGAX+6mCY5fRQS2BSw+FmIIv6j5AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Product", type text}, {"Volume(kg)", Int64.Type}, {"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Date.MonthName([Date])),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Date"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Volume(kg)", List.Sum)
    in
        #"Pivoted Column"

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Polly

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Samarth_18's avatar
    Samarth_18
    Community Champion

    Hi akarca ,

     

    Do you really need a seperate table since you can achieve this using Matrix Visual  by keeping the column as below:-

     

     

  • akarca's avatar
    akarca
    Frequent Visitor

    Hello Samarth_18 , because I will use these tables columns in other tables. Also, I will create different columns like this. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi akarca ,

    I have created a simple sample, please refer to my pbix fiel to see if it helps you.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY8xDsIwDEXvkgkkS7GdxElGoAdgYqk6IEAMgCqh9v4kLW1DxeDBfnrfdl2r47u99pdOgTq1z/512zzu29RU5+6mGqjVLjUxFSOzJi3zkDASRO8mxtoNbJ+ZxcIZ54fREQski8MDq9LAoGEQu9aGOCaD4ORvJLvogXh9Yo60IoVlyuNNYJh32S/JeRy4IKFwxPhlC2rGeQ8HDBOJE8iKCdGAX+6mCY5fRQS2BSw+FmIIv6j5AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Product", type text}, {"Volume(kg)", Int64.Type}, {"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Date.MonthName([Date])),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Date"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Volume(kg)", List.Sum)
    in
        #"Pivoted Column"

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Polly

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.