Forum Discussion

AlvinLy's avatar
AlvinLy
Helper II
2 years ago
Solved

Power Query - Generate table with lookups and blanks

Hello Fabric Community,

 

I've been using Power BI extensively but as I go into the dataverse I need to now do some of my transformations and coding in Power Query instead. I am making up a similar scenario and would like to see how to complete my desired table generation. Ok first, I have the following table I get

Activity IDCode TypeCode Value
1ColorRed
1SizeM
2ColorRed
3SizeL
4Color Blue
4Weight15
4SizeS
5SizeS
6LocationCity

 

My goal is to transform this table into the following (also as a note this is about 10 rows, my actual data has 10000+ rows with 20+ Code Types):

Activity IDColorSizeWeight Location
1RedM(blank/null)(blank/null)
2Red(blank/null)(blank/null)(blank/null)
3(blank/null)L(blank/null)(blank/null)
4BlueS15(blank/null)
5(blank/null)S(blank/null)(blank/null)
6(blank/null)(blank/null)(blank/null)City

 

So far I know I can use List.Distinct to extract both the distinct activity ID and the CodeTypes. I can also use Table.FromList to start turning into these tables. I'm struggling on combining the tables (one from Activity ID and one from Code Types) and also filling out this eventual blank table as shown above

 

I would appreciate any help/hint on this,

Thanks,

Alvin

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi AlvinLy ,

     

    check the [Code Type] and pivot the column:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLOz8kvAtJBqSlKsToQseDMqlQg5QsWMMKiyBihyAcsYIKkyCmnNBUuGJ6amZ5RAmQYmsLFoDqDwQKm6AJmIEPzkxNLMvPzQKZmllQqxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Activity ID" = _t, #"Code Type" = _t, #"Code Value" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Activity ID", Int64.Type}, {"Code Type", type text}, {"Code Value", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Code Type"]), "Code Type", "Code Value")
    in
        #"Pivoted Column"

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi AlvinLy ,

     

    check the [Code Type] and pivot the column:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLOz8kvAtJBqSlKsToQseDMqlQg5QsWMMKiyBihyAcsYIKkyCmnNBUuGJ6amZ5RAmQYmsLFoDqDwQKm6AJmIEPzkxNLMvPzQKZmllQqxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Activity ID" = _t, #"Code Type" = _t, #"Code Value" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Activity ID", Int64.Type}, {"Code Type", type text}, {"Code Value", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Code Type"]), "Code Type", "Code Value")
    in
        #"Pivoted Column"

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group