Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Conversion from a Row to Multiple Columns

Hi, 

This might be extremely basic questions for the expert user. But pretty tough for me. I have tried pivoting and unpivoting, however, couldn't get throug.

 

The original Dataset

DateNameValueAnnual Increment
01-Jul-22G191
02-Jul-22G24.52
03-Jul-22G303
04-Jul-22G35.54
05-Jul-22G415
01-Jul-22O46.5null
02-Jul-22O52null
03-Jul-22O57.5null
04-Jul-22O63null
05-Jul-22O68.5null
01-Jul-22C74null
02-Jul-22C79.5null
03-Jul-22C85null
04-Jul-22C90.5null
05-Jul-22C96null

 

The Required Shape

 

DateGOCAnnual Increment
01-Jul-221946.5741
02-Jul-2224.55279.52
03-Jul-223057.5853
04-Jul-2235.56390.54
05-Jul-224168.5965

 

Thank you for your assistance.

 

Regards,
Usman

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

    I created a sample pbix file(see attachment), please check if that is what you want...

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc47DoQwDATQu7iGFfEnkHoLJJo9QJQb0HL/jS2hYIvC4+JppKkV0nxc54wIE+z9UtGANlVAL8gf0WdG3mjRMOEgYi02E2+ceojJY8VPJVsrzlASvIECrKPDnjLdIAG20XlM+PZb+WWAQRkd8rS9DVAoy+hIoGzQ/g==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Value = _t, #"Annual Increment" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Value", type number}, {"Annual Increment", Int64.Type}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Annual Increment"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Name]), "Name", "Value", List.Sum),
        #"Added Index" = Table.AddIndexColumn(#"Pivoted Column", "Annual Increment", 1, 1, Int64.Type)
    in
        #"Added Index"

    Best Regards

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    I created a sample pbix file(see attachment), please check if that is what you want...

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc47DoQwDATQu7iGFfEnkHoLJJo9QJQb0HL/jS2hYIvC4+JppKkV0nxc54wIE+z9UtGANlVAL8gf0WdG3mjRMOEgYi02E2+ceojJY8VPJVsrzlASvIECrKPDnjLdIAG20XlM+PZb+WWAQRkd8rS9DVAoy+hIoGzQ/g==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Value = _t, #"Annual Increment" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Value", type number}, {"Annual Increment", Int64.Type}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Annual Increment"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Name]), "Name", "Value", List.Sum),
        #"Added Index" = Table.AddIndexColumn(#"Pivoted Column", "Annual Increment", 1, 1, Int64.Type)
    in
        #"Added Index"

    Best Regards

  • Hi

    The only way to get to your desired result is to have the Increment values in place of the nulls?  What should the logic be for plugging the increment values in the null cells?  Please clarify.