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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
JLYT
Frequent Visitor

Help with transforming data

Hi,

 

We are using Mongo Atlas as the database in our organisation which has a tag array and I am struggling to create a column for each tag key on Power BI.

 

Tables in Power Query appears like this:
content

content_idtag_id
1123
1234
1456
2234
2456

tag

idkeyvalue
123TypeVideo
234TypeAudio
456TopicHealth and Safety


I would like to have the table visual as:

content_idTypeTopic
1Video, AudioHealth and Safety
2AudioHealth and Safety


I would also like to be able to filter by each tag parameter. So for example, I need a slicer to say type = video. Then it will filter the table to show only content_id = 1.

 

Hope this makes sense!

 

Thanks

Jennifer

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@JLYT,

 

Try this in Power Query:

 

let
    Source = Table.NestedJoin(content, {"tag_id"}, tag, {"id"}, "tag", JoinKind.LeftOuter),
    ExpandTag = Table.ExpandTableColumn(Source, "tag", {"key", "value"}, {"tag.key", "tag.value"}),
    RemoveTagId = Table.RemoveColumns(ExpandTag,{"tag_id"}),
    ConcatValue = Table.Group(RemoveTagId, {"content_id", "tag.key"}, {{"tag.value", each Text.Combine([tag.value], ", "), type text}}),
    PivotKey = Table.Pivot(ConcatValue, List.Distinct(ConcatValue[tag.key]), "tag.key", "tag.value")
in
    PivotKey

 

DataInsights_0-1705442950809.png

 

Regarding filtering a visual by video (for example), use the DAX function CONTAINSSTRING.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@JLYT,

 

Try this in Power Query:

 

let
    Source = Table.NestedJoin(content, {"tag_id"}, tag, {"id"}, "tag", JoinKind.LeftOuter),
    ExpandTag = Table.ExpandTableColumn(Source, "tag", {"key", "value"}, {"tag.key", "tag.value"}),
    RemoveTagId = Table.RemoveColumns(ExpandTag,{"tag_id"}),
    ConcatValue = Table.Group(RemoveTagId, {"content_id", "tag.key"}, {{"tag.value", each Text.Combine([tag.value], ", "), type text}}),
    PivotKey = Table.Pivot(ConcatValue, List.Distinct(ConcatValue[tag.key]), "tag.key", "tag.value")
in
    PivotKey

 

DataInsights_0-1705442950809.png

 

Regarding filtering a visual by video (for example), use the DAX function CONTAINSSTRING.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Oh wow! This is great! Thank you so much!

 

For anyone else that is having similar issue, I created a blank query with the query above. Then I create a relationship between this new table id column and the original content column so that I can pull other columns in the original content table.

 

Thank you so much

Jennifer

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.