Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

TABLE TRANSFORMATION

Hi everyone, 

I am working on a table that looks like this in PowerBI:

TypeCategoryDateRecordsPartyActivity
MA-HPHP-Auth6/1/202012345vendorproduct
MA-HPHP-Auth6/1/2020556729vendorsales
MA-HPHP-Auth6/1/202023245clientproduct
MA-HPHP-Auth6/1/2020227823clientsales

 

I want to transform (compress) it into the table below but can't seem to know how to go about it in PowerBI/PowerQuery. I need urgent help please. 

 

TypeCategoryDatePartyProductSales
MA-HPHP-Auth6/1/2020vendor12345556729
MA-HPHP-Auth6/1/2020client23245227823
  • Anonymous's avatar
    Anonymous
    6 years ago

     

     

    you should select the column Activity then transform with the pivot Column tool 

     

     

     

     

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nVU0lHyCAASZvqG+kYGQIahkbEJkCpLzUvJLwIyCoryU0qTS5RidbAqNzUzt0BWXpyYk1qMS7GloYGhIZBOzslMzSshbLihsaEJsnKo4bEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Type = _t, Category = _t, Date = _t, Records = _t, Party = _t, Activity = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Category", type text}, {"Date", type date}, {"Records", Int64.Type}, {"Party", type text}, {"Activity", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Activity]), "Activity", "Records", List.Sum)
    in
        #"Pivoted Column"

     

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I guess the table was a little clumsy.

    This is what I am working on:

    TypeCategoryDateRecordsPartyActivity
    MAHP6/1/201234vendorproduct
    MAHP6/1/205678vendorsales
    MAHP6/1/2091011clientproduct
    MAHP6/1/201314clientsales

     

    This is how I want it to look like (transformed/compressed)

    TypeCategoryDatePartyProductSales
    MAHP6/1/20vendor12345678
    MAHP6/1/20client910111314

     

    • Anonymous's avatar
      Anonymous
      Not applicable

       

       

      you should select the column Activity then transform with the pivot Column tool 

       

       

       

       

       

       

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nVU0lHyCAASZvqG+kYGQIahkbEJkCpLzUvJLwIyCoryU0qTS5RidbAqNzUzt0BWXpyYk1qMS7GloYGhIZBOzslMzSshbLihsaEJsnKo4bEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Type = _t, Category = _t, Date = _t, Records = _t, Party = _t, Activity = _t]),
          #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Category", type text}, {"Date", type date}, {"Records", Int64.Type}, {"Party", type text}, {"Activity", type text}}),
          #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Activity]), "Activity", "Records", List.Sum)
      in
          #"Pivoted Column"

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Anonymous , many thanks. It worked like magic!