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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rob_vander2
Helper II
Helper II

count occurence of column value in DAX

Hi All,

 

I have below dataset which contains String as chain of activities. I can have many actvities in real scenarios. Requirements is that I want to give four filters as Activity 1, Activity 2 (eg. with value A,B & C as per the data) and Occurence 1 & Occurence 2 (eg. 1,2,3,4.. up to 10). For example if I select data from four filters as highlighted in screenshot in yellow, Activity 1 ="A"  & Occurence 1 ="3" is satiesfied by ID 1 & 2 as "A" is appeared 3 times in the String. Similarly other condition Activity 2 ="B" & Occurence 2 ="2" is satisfied by the ID 1 & 2. So both the condition is met by ID 1 & 2 which should be presented in the table output and count.

 

Note: There will be many activities in the filter, so user can select any combination of activities and corresponding occurence.

 

Hope the requirement is clear.

 

Screenshot 2025-04-22 at 16.49.17.png

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

You will want to rethink the UX as you would need to train your users not to specify conflicting filters.

 

lbendlin_0-1745349527306.png

 

View solution in original post

kushal_chawda
Frequent Visitor

@rob_vander2  try below

 

Use conditional measure for table visual

 

Conditional = 
if( (LEN(max('Table'[String])) - LEN(SUBSTITUTE(max('Table'[String]), SELECTEDVALUE(Filter1[Activity1]), ""))) = SELECTEDVALUE(Filter3[Occurrence1]) &&
(LEN(max('Table'[String])) - LEN(SUBSTITUTE(max('Table'[String]), SELECTEDVALUE(Filter2[Activity2]), ""))) = SELECTEDVALUE(Filter4[Occurrence2]),1,BLANK())

 

Use count measure to count the ID

 

count = 
CALCULATE(
        COUNT('Table'[ID]),
    (LEN('Table'[String]) - LEN(SUBSTITUTE('Table'[String], SELECTEDVALUE(Filter1[Activity1]), ""))) = SELECTEDVALUE(Filter3[Occurrence1]),
    (LEN('Table'[String]) - LEN(SUBSTITUTE('Table'[String], SELECTEDVALUE(Filter2[Activity2]), ""))) = SELECTEDVALUE(Filter4[Occurrence2])
)

 

kushal_chawda_0-1745447281278.pngkushal_chawda_1-1745447317589.png

 

View solution in original post

7 REPLIES 7
v-shamiliv
Community Support
Community Support

Hi @rob_vander2 
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.


v-shamiliv
Community Support
Community Support

Hi @rob_vander2 
I wanted to check if you had the opportunity to review the information provided by @lbendlin and @kushal_chawda . Please feel free to contact us if you have any further questions. If their response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

v-shamiliv
Community Support
Community Support

Hi @rob_vander2 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

kushal_chawda
Frequent Visitor

@rob_vander2  try below

 

Use conditional measure for table visual

 

Conditional = 
if( (LEN(max('Table'[String])) - LEN(SUBSTITUTE(max('Table'[String]), SELECTEDVALUE(Filter1[Activity1]), ""))) = SELECTEDVALUE(Filter3[Occurrence1]) &&
(LEN(max('Table'[String])) - LEN(SUBSTITUTE(max('Table'[String]), SELECTEDVALUE(Filter2[Activity2]), ""))) = SELECTEDVALUE(Filter4[Occurrence2]),1,BLANK())

 

Use count measure to count the ID

 

count = 
CALCULATE(
        COUNT('Table'[ID]),
    (LEN('Table'[String]) - LEN(SUBSTITUTE('Table'[String], SELECTEDVALUE(Filter1[Activity1]), ""))) = SELECTEDVALUE(Filter3[Occurrence1]),
    (LEN('Table'[String]) - LEN(SUBSTITUTE('Table'[String], SELECTEDVALUE(Filter2[Activity2]), ""))) = SELECTEDVALUE(Filter4[Occurrence2])
)

 

kushal_chawda_0-1745447281278.pngkushal_chawda_1-1745447317589.png

 

lbendlin
Super User
Super User

You will want to rethink the UX as you would need to train your users not to specify conflicting filters.

 

lbendlin_0-1745349527306.png

 

@lbendlin  Could you explain how this DAX measure works?

Line 2 -  bring the data into a usable format. In DAX pretty much the only usable way is to use PATH functions so you replace whatever delimiter you have with a pipe.

Line 3 - materialize the elements of the list (ie the items of the path) into a table

Line 4 - group the table by the elements and add a occurrence count for each

Line 5 - compare the table with the filter settings. Both filters need to match so we only return success if the sum of these two tests is 2.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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