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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply

tack count of matched items from the selected category

Hi team,
I am having a table called Category where i have two columns "Category" and "Items"
I am applying category in filter and i wanted to have count of matched items from the selected categories

can anyone give me DAX to acheive it

Thanks

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

Hi @rajeshapunu1234 ,

 

I am not sure if I understood your question correctly.
Based on the example and description you provided, please try code as below to create a measure.
My Sample:

vweiyan1msft_0-1709111534882.png

Count of matched items = 
VAR Sel_Category = SELECTEDVALUE ( 'Table'[Category] )
VAR Category_Trim =
    SUBSTITUTE ( SUBSTITUTE ( Sel_Category, "Category", "item" ), " ", "" )
RETURN
    COUNTX ( FILTER ( 'Table', 'Table'[Items] = Category_Trim ), 'Table'[Items] )

When you select "Category 1" in the slicer, Result is as below.

vweiyan1msft_1-1709111567277.png

Is this the result you expect?
Please correct me if I misunderstood your needs.


Best Regards,
Yulia Yan


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

7 REPLIES 7
v-weiyan1-msft
Community Support
Community Support

Hi @rajeshapunu1234 ,

 

I am not sure if I understood your question correctly.
Based on the example and description you provided, please try code as below to create a measure.
My Sample:

vweiyan1msft_0-1709111534882.png

Count of matched items = 
VAR Sel_Category = SELECTEDVALUE ( 'Table'[Category] )
VAR Category_Trim =
    SUBSTITUTE ( SUBSTITUTE ( Sel_Category, "Category", "item" ), " ", "" )
RETURN
    COUNTX ( FILTER ( 'Table', 'Table'[Items] = Category_Trim ), 'Table'[Items] )

When you select "Category 1" in the slicer, Result is as below.

vweiyan1msft_1-1709111567277.png

Is this the result you expect?
Please correct me if I misunderstood your needs.


Best Regards,
Yulia Yan


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

CupidC
Helper II
Helper II

 

CupidC_0-1709014574607.pngCupidC_1-1709014586732.png

 

This dax giving distince count of the selected category
but the need is count of matched items only 

 

Example
Category 1  item1
Category 1  item2

Category 2  item1

Category 2  item3

Category 3  item1

Category 3  item4


from the above table the output of matched item count should be 1 as "Item1" available in the all three category
your result is giving 4 as it count distince of the all items not only matched items

thanks

Hi @rajeshapunu1234 

Please use 
ItemsQty = COUNT('yourtable'[itemid])


Let me know if that works for you


If your requirement is solved, please mark THIS ANSWER as SOLUTION ✔️ and help other users find the solution quickly. Please hit the Thumbs Up 👍 button if this comment helps you.

Thanks
Pijush
Linkedin




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





no this also not giving the matched count
I wanted to have matched count only
please suggest DAX

Hi @rajeshapunu1234 

I am using TableCategoryItem

Category 1Item A
Category 1Item B
Category 2Item A
Category 2Item B
Category 2Item C
Category 2Item D
Category 3Item A
Category 3Item B
Category 3Item C

The measure working 

PijushRoy_0-1709014175530.png

Find the PBIX and if it will not working in your data model,
Please share smaple PBIX file link 
https://drive.google.com/file/d/160Mz1MriG4-yoYb8smaqUQn00wU17CP8/view?usp=sharing

 


Let me know if that works for you


If your requirement is solved, please mark THIS ANSWER as SOLUTION ✔️ and help other users find the solution quickly. Please hit the Thumbs Up 👍 button if this comment helps you.

Thanks
Pijush
Linkedin




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Ritaf1983
Super User
Super User

Hi @rajeshapunu1234 

A standard distinct count will do the work (if you need the distinct counts).
ItemsQty = distinctcount('yourtable'[itemid])

Or count rows if you need to count duplicates too
ItemsQty = countrows('yourTable')


If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors