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
TJohnson6754
Frequent Visitor

How to visualize count of list components in column

Hi there,

I'm newer at this and need help with what seems like it should be simple but hasn't been (for me) so far:

 

My table contains a column that contains list data.

 

Example data: 

IDList
1dog,cat,iguana
2horse,dog
3cat,hamster
4horse,iguana
5
horse,cat,hamster

 

I want to be able to visualize the data in Power BI similar to this:

TJohnson6754_0-1675117566539.png

What I've tried:

  • I made measures, each measure counts one component in the column, then I'm unable to add the measures to visualize them as separate bars on the bar chart.
  • I've made separate columns for each list component, each one with a 1 or 0 depending on whether that row contains the list component of interest.
  • I tried using dax to make new tables, one for each list component, with the intention to append them to one another, but I wasn't able to append these types of tables in "Transform Data". 
    • PetsDog = SELECTCOLUMNS(FormResponses,"Pet",if(CONTAINSSTRING(FormResponses[List],"dog"),"dog",""))​
    • PetsCat = SELECTCOLUMNS(FormResponses,"Pet",if(CONTAINSSTRING(FormResponses[List],"cat"),"cat",""))​
    • etc.

 

 

Is there a simple (or complicated) way to do this?

1 ACCEPTED SOLUTION
alekhved
Resolver I
Resolver I

hi @TJohnson6754 

 

I created a temp table just like the table shown above and followed the certain steps in Power BI Query editor to create a new table which could help solve your problem.

 

Temp Table

 

alekhved_0-1675123136529.png

 

 

 

Steps followed in Query Editor

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUrJT9dJTizRyUwvTcxLVIrViVYyAgpn5BcVp+oAJcEixkARkKKMxNziktQipdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, List = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"List", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "List", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"List.1", "List.2", "List.3"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"List.1", type text}, {"List.2", type text}, {"List.3", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"ID"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
#"Removed Columns"

 

Output at end of all steps

 

alekhved_1-1675123180308.png

 

Again, this solution is based on assumption that you have  "," as delimiter. And you are not much worried about multiple records with the same ID (different list name though)

 

Hope this helps!!

alekh

 

View solution in original post

2 REPLIES 2
alekhved
Resolver I
Resolver I

hi @TJohnson6754 

 

I created a temp table just like the table shown above and followed the certain steps in Power BI Query editor to create a new table which could help solve your problem.

 

Temp Table

 

alekhved_0-1675123136529.png

 

 

 

Steps followed in Query Editor

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUrJT9dJTizRyUwvTcxLVIrViVYyAgpn5BcVp+oAJcEixkARkKKMxNziktQipdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, List = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"List", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "List", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"List.1", "List.2", "List.3"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"List.1", type text}, {"List.2", type text}, {"List.3", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"ID"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
#"Removed Columns"

 

Output at end of all steps

 

alekhved_1-1675123180308.png

 

Again, this solution is based on assumption that you have  "," as delimiter. And you are not much worried about multiple records with the same ID (different list name though)

 

Hope this helps!!

alekh

 

This worked for me, thank you so much!

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.