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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
my_username
Frequent Visitor

Calculate a number of occurrences of unique items within column

I am new to Power BI and I need help on how to measure number of occurences of items within column.

Here is an example:

I have columns c1 (text), and c2 (text). In c2, items are separated by comma.

my_username_0-1666294768375.png

I need to calculate the number of unique items in c2 for chosen c1, for example:

- if {1} is selected for c1, I will have 3 unique items in c2: {a,b,c}

- if {2,3} is selected for c1, I will have 4 unique items in c2: {a,b,c,d}

and so on.

 

Any help is appreciated!

1 ACCEPTED SOLUTION

Thanks for the clarification.  Apologies for the mis-interpretation.

The easiest way to handle this is to use Power Query to split your column [c2] into rows.

rsbin_5-1666302175554.png

 

Then use DistinctCount in Dax: 

DistinctItems = DISTINCTCOUNT( Items[c2] )

rsbin_4-1666301958322.png

Hope this is what you after.

Regards,

View solution in original post

3 REPLIES 3
rsbin
Community Champion
Community Champion

@my_username ,

This should work for you:

Item_Count = IF(LEN(TRIM([c2]))=0,0,LEN([c2])-LEN(SUBSTITUTE([c2],",",""))+1)

c1c2Item_Count

1 a,b,c 3
2 b,c 2
3 a,c,d 3

Used the link below.  If you need to modify, this should be a good resource.

https://learn.microsoft.com/en-us/office/troubleshoot/excel/formulas-to-count-occurrences-in-excel

Although it says "excel", a little modification and it works in DAX.  The text functions are the same.

 

Trust this works for you.

Regards,

 

Thank you for your responce. I don't think that this is exactly what I need.

Because if I want to calculate values for c1 selected as {1,3}, then the count of unique items would be 4, because  cumulutive c2 would be {a,b,c,a,c,d} -> filter out for unique -> {a,b,c,d} -> 4 items. This is my main challenge.

Thanks for the clarification.  Apologies for the mis-interpretation.

The easiest way to handle this is to use Power Query to split your column [c2] into rows.

rsbin_5-1666302175554.png

 

Then use DistinctCount in Dax: 

DistinctItems = DISTINCTCOUNT( Items[c2] )

rsbin_4-1666301958322.png

Hope this is what you after.

Regards,

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.