Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

COnvert rows as column headers

Hi all,

I have loaded below data into desktop.

serviceSUb groupattributevalue
auditlogjan8
auditlogfeb9
auditlogmar10
auditlogapr11
auditlogmay12
auditafcjan6
auditafcfeb7
auditafcmar8
auditafcapr9
auditafcmay10
auditcnfjan11
auditcnffeb12
auditcnfmar13
auditcnfapr14
auditcnfmay15
auditrbgjan16
auditrbgfeb17
auditrbgmar18
auditrbgapr19
auditrbgmay20
debuglogjan14
debuglogfeb15
debuglogmar16
debuglogapr17
debuglogmay18
debugafcjan19
debugafcfeb20
debugafcmar5
debugafcapr6
debugafcmay7
debugcnfjan8
debugcnffeb9
debugcnfmar10
debugcnfapr1
debugcnfmay2
debugrbgjan3
debugrbgfeb4
debugrbgmar5
debugrbgapr5
debugrbgmay6

 

Now, in query editor need to conert sub group values as headers in below format.

serviceattributelogafccnfrbg
auditjan861116
auditfeb971217
auditmar1081318
auditapr1191419
auditmay12101520
debugjan141983
debugfeb152094
debugmar165105
debugapr17615
debugmay18726

Can any body please help on this ASAP.

 

 

Thanks

Praneeth

  • Hi Anonymous, 

     

    You can select the column SUb group then click on the Pivot Column: 

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZPLDoIwEEV/xXTNQlRe32FcERctFoJRIJWa8PcWZsQW72bS9OQmJ9PbshQvbd5tpUUkzhe1a0xvB3eW42haZcf5/i0fVotrVAppb+3obh594+Zddm7mgNRauVkA8pTGzXgPkBwWFMPUNKNDgGRdrRIpICSRAUISOSDkUMDM9C9edfWqsBEnRA4bcUK8iSNAvIkTTC0aSYCM+j1HnALEGhlArJEDxBoFTM0aB9rGTSvbbFrB8iFijQQg1kgBYo0Mpqaf/Bf5vWD5EJHGRt5vRgIIWaQwM609+xK/GDkg/gcJSfBBQsSLgKHlOQLil+IICCmcAEFL8BuBCBm49Vw/", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"service", type text}, {"SUb group", type text}, {"attribute", type text}, {"value", Int64.Type}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[#"SUb group"]), "SUb group", "value", List.Sum)
    in
        #"Pivoted Column"

     

     

    Best Regards,
    Qiuyun Yu 

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi All,

     

    I have data like below and loaded into power bi desktop.

    serviceSUb groupattributevalue
    auditlogjan8
    auditlogfeb9
    auditlogmar10
    auditlogapr11
    auditlogmay12
    auditlogjan6
    auditlogfeb7
    auditlogmar8
    auditlogapr9
    auditlogmay10
    auditcnfjan11
    auditcnffeb12
    auditcnfmar13
    auditcnfapr14
    auditcnfmay15
    auditcnfjan16
    auditcnffeb17
    auditcnfmar18
    auditcnfapr19
    auditcnfmay20
    debuglogjan14
    debuglogfeb15
    debuglogmar16
    debuglogapr17
    debuglogmay18
    debuglogjan19
    debuglogfeb20
    debuglogmar5
    debuglogapr6
    debuglogmay7
    debugcnfjan8
    debugcnffeb9
    debugcnfmar10
    debugcnfapr1
    debugcnfmay2
    debugcnfjan3
    debugcnffeb4
    debugcnfmar5
    debugcnfapr5
    debugcnfmay6

     

    After laoding data into power bi I want transpose it into below format by using query editor.

    serviceattributelogafccnfrbg
    auditjan861116
    auditfeb971217
    auditmar1081318
    auditapr1191419
    auditmay12101520
    debugjan141983
    debugfeb152094
    debugmar165105
    debugapr17615
    debugmay18726

    Please help me if any have solution for this.

     

    Thanks

    Praneeth

    • parry2k's avatar
      parry2k
      Super User

      Anonymous based on dataset you provided, are you lookig for following result

       

  • v-qiuyu-msft's avatar
    v-qiuyu-msft
    Community Support

    Hi Anonymous, 

     

    You can select the column SUb group then click on the Pivot Column: 

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZPLDoIwEEV/xXTNQlRe32FcERctFoJRIJWa8PcWZsQW72bS9OQmJ9PbshQvbd5tpUUkzhe1a0xvB3eW42haZcf5/i0fVotrVAppb+3obh594+Zddm7mgNRauVkA8pTGzXgPkBwWFMPUNKNDgGRdrRIpICSRAUISOSDkUMDM9C9edfWqsBEnRA4bcUK8iSNAvIkTTC0aSYCM+j1HnALEGhlArJEDxBoFTM0aB9rGTSvbbFrB8iFijQQg1kgBYo0Mpqaf/Bf5vWD5EJHGRt5vRgIIWaQwM609+xK/GDkg/gcJSfBBQsSLgKHlOQLil+IICCmcAEFL8BuBCBm49Vw/", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"service", type text}, {"SUb group", type text}, {"attribute", type text}, {"value", Int64.Type}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[#"SUb group"]), "SUb group", "value", List.Sum)
    in
        #"Pivoted Column"

     

     

    Best Regards,
    Qiuyun Yu