Forum Discussion

Gurps's avatar
Gurps
Frequent Visitor
3 years ago
Solved

How to extract each value from a range into a separate table?

I have one table, let's call it "User Dimension Values"  that has the following layout:

 

User IDDimensionDimension Values
User ADimension A100..208
User BDimension A100..202|204..205

 

This is linked with another table, let's call it "Dimension Table" which will have the following layout:

 

Dimension CodeCode
Dimension A050
Dimension A100
Dimension A201
Dimension A202
Dimension A203
Dimension A204
Dimension A205
Dimension A208

 

I want to use Power Query to create a third table inside Power Bi which would then have the following format:

 

 

User IDDimensionCode
User ADimension A100
User A Dimension A201
User A Dimension A202
User A Dimension A203
User A Dimension A204
User A Dimension A205
User A Dimension A208
User B Dimension A100
User B Dimension A201
User B Dimension A202
User B Dimension A204
User B Dimension A205

 

So how do I take the values in the "Dimension Values" column from the "User Dimension Values" Table and use the ranges such as 

  • 100..208
  • 100..202|204..205

To then produce a table that will show me row by row each dimension value assigned to each user from the range?

 

Thanks

 

 

 

  • More simple

    let
    Source = #"User Dimension Values",
    List = Table.AddColumn(Source, "Dimension Values 2", each Expression.Evaluate("{" & Text.Replace([Dimension Values], "|", "} & {") & "}")),
    Expand = Table.ExpandListColumn(List, "Dimension Values 2"),
    Join_Inner = Table.NestedJoin(Expand, {"Dimension", "Dimension Values 2"}, #"Dimension Table", {"Dimension Code", "Code"}, "Dimension Table", JoinKind.Inner)
    in
    Join_Inner

    Stéphane 

3 Replies

  • More simple

    let
    Source = #"User Dimension Values",
    List = Table.AddColumn(Source, "Dimension Values 2", each Expression.Evaluate("{" & Text.Replace([Dimension Values], "|", "} & {") & "}")),
    Expand = Table.ExpandListColumn(List, "Dimension Values 2"),
    Join_Inner = Table.NestedJoin(Expand, {"Dimension", "Dimension Values 2"}, #"Dimension Table", {"Dimension Code", "Code"}, "Dimension Table", JoinKind.Inner)
    in
    Join_Inner

    Stéphane 

    • Gurps's avatar
      Gurps
      Frequent Visitor

      That's incredible.  Thank you so much for the solution.  

  • Hi

    Split "Dimension Values"  by "|" into rows

    Convert "100..208" into list with Expression.Evaluate

    Expand list

    Join with "Dimension Values"  (joinkind = Inner)

     

    let
    Source = #"User Dimension Values",
    Split = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Dimension Values", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Dimension Values"),
    Convert_to_list = Table.TransformColumns(Split, {{"Dimension Values", each Expression.Evaluate("{"&_&"}")}}),
    Expand = Table.ExpandListColumn(Convert_to_list, "Dimension Values"),
    Join_Inner = Table.NestedJoin(Expand, {"Dimension", "Dimension Values"}, #"Dimension Table", {"Dimension Code", "Code"}, "Dimension Table", JoinKind.Inner)
    in
    Join_Inner

     

     Stéphane