Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gk2go
Helper II
Helper II

How to convert list in a field into a relational table

A have this table imported from CSV:

|| URL | Title | Tags ||

website.com/page-a | Page A | Tag-1; Tag-2

website.com/page-b | Page B | Tag-3; Tag-2

website.com/page-c | Page C | Tag-1; Tag-2

 

How can i convert it into the following?

 

1. Tags Table

|| Tag ||

Tag-1

Tag-2

Tag-3

 

2. Page-Tags Table

|| Page | Tag ||

website.com/page-a | Tag-1

website.com/page-a | Tag-2

website.com/page-b | Tag-3

website.com/page-b | Tag-2

website.com/page-c | Tag-1

website.com/page-c | Tag-2

 

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Starting with your input table and calling that query "RawData", you can use these two M queries to get your two tables.  Put the text over the default text of a blank query.  You can right click on the RawData and uncheck "Enable Load" to not load that into your model.

 

 

let
    Source = RawTable,
    #"Added Custom" = Table.AddColumn(Source, "TagsList", each Text.Split([Tags], "; ")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Tags", "Title"}),
    #"Expanded TagsList" = Table.ExpandListColumn(#"Removed Columns", "TagsList"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded TagsList",{{"URL", "Page"}, {"TagsList", "Tags"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Tags", type text}})
in
    #"Changed Type"


let
    Source = RawTable,
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Tags"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Text.Split([Tags], "; ")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Other Columns1" = Table.SelectColumns(#"Expanded Custom",{"Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns1",{{"Custom", "Tags"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Tags", type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type")
in
    #"Removed Duplicates"

 

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

V-pazhen-msft
Community Support
Community Support

@gk2go 


Please follow the steps:

1. Split Tag column by "; " =>Make a copy of the table name it Table2

2. Remove Tags.2 in Table 1=>Remove Tags.1 in Table 2 => Rename the remaining Tags columns in both table as a same name e.g. "Tag".

3. Append Table 2 into Table 1 =>Right click Table 2 uncheck Enable load.

V-pazhen-msft_2-1611123317331.png

4. Right click the Tag column=>click "Add as new Query"=>Remove duplicates and convert to table. 

V-pazhen-msft_4-1611123471627.png

5. Close and Apply, add a relationship between Table 1 and Tag table.


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
V-pazhen-msft
Community Support
Community Support

@gk2go 


Please follow the steps:

1. Split Tag column by "; " =>Make a copy of the table name it Table2

2. Remove Tags.2 in Table 1=>Remove Tags.1 in Table 2 => Rename the remaining Tags columns in both table as a same name e.g. "Tag".

3. Append Table 2 into Table 1 =>Right click Table 2 uncheck Enable load.

V-pazhen-msft_2-1611123317331.png

4. Right click the Tag column=>click "Add as new Query"=>Remove duplicates and convert to table. 

V-pazhen-msft_4-1611123471627.png

5. Close and Apply, add a relationship between Table 1 and Tag table.


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

mahoneypat
Employee
Employee

Starting with your input table and calling that query "RawData", you can use these two M queries to get your two tables.  Put the text over the default text of a blank query.  You can right click on the RawData and uncheck "Enable Load" to not load that into your model.

 

 

let
    Source = RawTable,
    #"Added Custom" = Table.AddColumn(Source, "TagsList", each Text.Split([Tags], "; ")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Tags", "Title"}),
    #"Expanded TagsList" = Table.ExpandListColumn(#"Removed Columns", "TagsList"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded TagsList",{{"URL", "Page"}, {"TagsList", "Tags"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Tags", type text}})
in
    #"Changed Type"


let
    Source = RawTable,
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Tags"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Text.Split([Tags], "; ")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Other Columns1" = Table.SelectColumns(#"Expanded Custom",{"Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns1",{{"Custom", "Tags"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Tags", type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type")
in
    #"Removed Duplicates"

 

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors