Forum Discussion

Sudharshan1919's avatar
Sudharshan1919
Helper III
4 years ago
Solved

Pivoting Error

Hey Hi Guys, I am new to Power BI and facing some basic issues. Appreciate if anyone could help. I have one issue at Pivoting the elements. I am calling this API ("https://management.azure.com/...
  • Thingsclump's avatar
    4 years ago

    Hi @Sudharshan1919 

     

    Here you go if you want to do it PQ. the trick is you have to tell PQ that every 4 rows should be treated as a single row after pivoting. so I have added index,divide and round up. use the code that i have pasted at last.

     

     

     

     

     

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsssKilNzPFNTM7IzEstVtJRcjQEEmXOAaEgjqFSrA5ORb6puflFlSBVeuam+BSCTUssS8zMSUzKSSVkLEh1cEFqUXJ+EVFqQRwjotxpRKo78RqL5k6g2lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [resourcetype = _t, valuename = _t, capabilitiesname = _t, capabilityvalue = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"resourcetype", type text}, {"valuename", type text}, {"capabilitiesname", type text}, {"capabilityvalue", type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 4), type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Modulo",{"Modulo"}),
    #"Divided Column" = Table.TransformColumns(#"Removed Columns", {{"Index", each _ / 4, type number}}),
    #"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[capabilitiesname]), "capabilitiesname", "capabilityvalue")
    in
    #"Pivoted Column"

     

     

     

    Thanks,

    thingsclump

    www.thingsclump.com 

     

    accpet solution if this works for you.