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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Graph count of items in a column with multiple items per row

Given this type of data:

 

DudaPBI.jfif

 

Suppose I want to make two different graphs, one for the individual count of the items in the Order column and one for the Pets column. What would be the simplest way to do this?

Note that I want to graph the count of each item, and not group of items. This way I'd obtain a count of 4 - Burger, 2 - Pizza, and not 1- Burger, 1 - Pizza, Coke and so on.

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could change “,” to “|” in power query . Then create a new table in Power BI , Finally count of “Order” and “Pets” , the following formula to create :

Step1: Duplicate Order 、Pets columns

Step2: Replace Order 、Pets columns(“,” ->”|”)

v-yalanwu-msft_0-1623732880358.png

Step3:Create new table

NewTable = 
var _a=SELECTCOLUMNS('Table',"order",PATHITEM([Order2],1,TEXT),"pets",PATHITEM([Pets2],1,TEXT))
var _b=SELECTCOLUMNS('Table',"order",PATHITEM([Order2],2,TEXT),"pets",PATHITEM([Pets2],2,TEXT))
var _c=SELECTCOLUMNS('Table',"order",PATHITEM([Order2],3,TEXT),"pets",PATHITEM([Pets2],3,TEXT))
return UNION(_a,_b,_c)

Step4:Create two measures to calculate count

ordercount = COUNT('NewTable'[order])
percount = COUNT('NewTable'[pets])

The final output is shown below:

v-yalanwu-msft_4-1623734064501.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

View solution in original post

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could change “,” to “|” in power query . Then create a new table in Power BI , Finally count of “Order” and “Pets” , the following formula to create :

Step1: Duplicate Order 、Pets columns

Step2: Replace Order 、Pets columns(“,” ->”|”)

v-yalanwu-msft_0-1623732880358.png

Step3:Create new table

NewTable = 
var _a=SELECTCOLUMNS('Table',"order",PATHITEM([Order2],1,TEXT),"pets",PATHITEM([Pets2],1,TEXT))
var _b=SELECTCOLUMNS('Table',"order",PATHITEM([Order2],2,TEXT),"pets",PATHITEM([Pets2],2,TEXT))
var _c=SELECTCOLUMNS('Table',"order",PATHITEM([Order2],3,TEXT),"pets",PATHITEM([Pets2],3,TEXT))
return UNION(_a,_b,_c)

Step4:Create two measures to calculate count

ordercount = COUNT('NewTable'[order])
percount = COUNT('NewTable'[pets])

The final output is shown below:

v-yalanwu-msft_4-1623734064501.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

ChrisMendoza
Resident Rockstar
Resident Rockstar

Here's the table so I can come back to this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY/LCsMgEEV/RWbtT6SWPhYtWXUTXAzpECRGwSSkzdd3lMYKga686vF6pmngTD50BBIOM6+Bw9F3oGUDlXPI29qsK0qhfB8phVO6vGF450dSnIKhMUPcwPlLVpZev5oE7hD3DLTw6bUloQLhwPmCwzixUARqnG3xW4mlopK9m7aPotlXih0T++Jsm80m8kBL/+cCrT8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Order = _t, Pets = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Order", type text}, {"Pets", type text}})
in
    #"Changed Type"





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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