Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Unpivoting and Pivoting Rows

Hello Power BI Community,   I am having an issue with Pivoting a table in Power Query Editor after I unpivot some columns and could use some help. I'm sure it's something simple, but I have tried t...
  • lbendlin's avatar
    lbendlin
    1 year ago
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lVXJaiRHEP2VRug2QRJLrlfrNDDGZhZfBh0aTWHESN2gGRn8936RmYXbdJcbnSoiqyqW9+JFfv168+uXD7/d7d7tlrvj8/Puhm7u9odvf7vx+fhz/7T7cnj8ufvj+PT6vOBMyHImjXXY0ki5TDvivA2bC5Vs8zxRsnZzTxdyfTp+22+lslao9iBRG2XxNDF5sAQrsRFLt0xJmC8nuDsevz8uP7ZyJBPikmcUrj1ezFTV86aCvLl0S9CcbeRYAftl/2M5w0tLpojyuo3yRcq0mazpsGOjVOs8r1Q4/z9eFzJZrJR72ZbRVPJoVr0BbyoKwIzardata3BdSBE1USuDEabMPbAhnPXAKRNHbzRGobyZYkXr/eHhZXleDuesVK/Q68+RuHnEbFRTJ6KSlM4SSLINQlaUtjMAb+2l5kop+dDmRLX4SQVFvUcRdTKuArWdRRixeMQSirUPAWdqTdxSA2F9GHy+Wa7gdTK/H5e/lsOrp7gtJA3Csxqqk3Dr0QuZxVDb9AvA4xpaXP1EUSSojv/ZilcUykarFzR6kj9C7Kg+crA4/ITBxjCHDiv8Jr4MJHTZ3npuUJc1xOlnfC+or27siMsSPikB+wgttyKhSwu+AVptFiQPPxVQyTEkni17iVZCm5DVBva1hLIhuwsK/0/+qkpFJTQbfvG1whq6QtyH5rilkGa+AvkklpDb+n/t38sVCi6md3bBQiyhK8R9CKhUtDMZUGGkl9B3AvyIGQcEoU7GYsbui5iQ9IatcFIBplyjL62gefjsygXHfTHANwDuFXXNwU8F7wUNz/cxN7LKga+t2DOxnQKBJZ0kz8FX3FNmOpvUhALFQl+B3WvcJh+KAW61+cC+bZ2cQgCpa9NQxgRmBikAeMwbbsOcmwsMXsNsVMgv+w64FZIK7lNzeb5505wUIL61SHMMbQbWhCVnK8vwFTtIShAefsTFlDTNIuErLipMUbnGwcflz9en/cvu95fHh9H8qu1geT7LfNbx3LoMVmjPQgqvffDEVFY4/cSmkbdq/Re089Aa2FYjTmNsDhhjK8JA6ff3/wA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Market = _t, Product = _t, Metrics = _t, #"09/03/2023" = _t, #"09/10/2023" = _t, #"09/17/2023" = _t, #"09/24/2023" = _t, #"10/01/2023" = _t]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Market", "Product", "Metrics"}, "Date", "Value"),
        #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Currency.Type}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Metrics]), "Metrics", "Value")
    in
        #"Pivoted Column"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.