Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi
I have the following table:
| Food Category | Food |
| American | Hot Dogs |
| Irish | Hot Dogs |
| Italian | Pasta |
| American | Fries |
| Irish | Ham and Cabbage |
| Irish | Shepherds pie |
| American | Corn Dogs |
I would like to create three measures for the following:
Count: 2 are only American (Fries, Corn Dogs) - non-repeated values in Food Column
Count: 1 are American and Irish (Hot Dogs) - repeated values in Food Column
Count: 1 are Italian (Pasta) etc..
I am creating a Venn Diagram so will need to get these counts for each area of it.
Thanks in advance.
Regards,
Laura
Solved! Go to Solution.
Hi @Lauraeire_81 ,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
Regards,
Chaithanya
Hi @Lauraeire_81 ,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
Regards,
Chaithanya
Hiii @Lauraeire_81
Hello @Lauraeire_81
Please try using these measures and see if it fulfils your requirement.
Count_American_Only =
CALCULATE (
DISTINCTCOUNT (FoodCategory[Food]),
FoodCategory[Food Category] = "American",
NOT (
FoodCategory[Food] IN
CALCULATETABLE (
VALUES (FoodCategory[Food]),
FoodCategory[Food Category] <> "American"
)
)
)
Count_American_and_Irish =
CALCULATE (
DISTINCTCOUNT (FoodCategory[Food]),
FoodCategory[Food] IN
CALCULATETABLE (
VALUES (FoodCategory[Food]),
FoodCategory[Food Category] = "American"
),
FoodCategory[Food] IN
CALCULATETABLE (
VALUES (FoodCategory[Food]),
FoodCategory[Food Category] = "Irish"
)
)
Count_Italian_Only =
CALCULATE (
DISTINCTCOUNT (FoodCategory[Food]),
FoodCategory[Food Category] = "Italian",
NOT (
FoodCategory[Food] IN
CALCULATETABLE (
VALUES (FoodCategory[Food]),
FoodCategory[Food Category] <> "Italian"
)
)
)
I hope the solution I provided helps! If it works for you and solves your issue, please feel free to mark it as a solution so it can assist others who may have the same problem.
HI @bhanu_gautam Thank you this helps.
What does EARLIER mean? Also if I had a slicer with 3 values (American, Irish, Italian), can you show me how this works with those measures above?
I'd like to leave all values as '0' if there are no slicer values selected.
Thanks for your help.
Regards,
Laura
@Lauraeire_81 The EARLIER function in DAX is used to refer to an earlier row context in a nested row context
To incorporate a slicer with values (American, Irish, Italian) and ensure that the measures return '0' if no slicer values are selected, you can modify the measures to include a check for the slicer selection. Here are the updated measures:
dax
CountOnlyAmerican =
IF(
ISFILTERED('Table'[Category]),
CALCULATE(
COUNTROWS(
FILTER(
VALUES('Table'[Food]),
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "American")
) = 1 &&
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] <> "American")
) = 0
)
)
),
0
)
dax
CountAmericanAndIrish =
IF(
ISFILTERED('Table'[Category]),
CALCULATE(
COUNTROWS(
FILTER(
VALUES('Table'[Food]),
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "American")
) > 0 &&
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "Irish")
) > 0
)
)
),
0
)
dax
CountItalian =
IF(
ISFILTERED('Table'[Category]),
CALCULATE(
COUNTROWS(
FILTER(
VALUES('Table'[Food]),
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "Italian")
) > 0
)
)
),
0
)
These measures use the ISFILTERED function to check if the slicer is applied to the 'Category' column. If the slicer is not applied, the measures return '0'. If the slicer is applied, the measures perform the calculations as described.
Proud to be a Super User! |
|
Thanks @bhanu_gautam it gives me back a count of '3' when American is selected. Can you please send me the powerbi pbx file ? Thanks for your help.
Please try the following:
Measure01 =
CALCULATE (
DISTINCTCOUNT ( _data[Food Category] ),
KEEPFILTERS ( _data[Food] IN {"Hot Dogs", "Fries"} )
)
Measure02 =
CALCULATE (
DISTINCTCOUNT ( _data[Food Category] ),
KEEPFILTERS ( _data[Food] = "Hot Dogs" )
)
Measure03 =
CALCULATE (
DISTINCTCOUNT ( _data[Food Category] ),
KEEPFILTERS ( _data[Food] = "Pasta" )
)
@Lauraeire_81 Create measure
Count of Foods that are only American (non-repeated values in Food Column):
DAX
CountOnlyAmerican =
CALCULATE(
COUNTROWS(
FILTER(
VALUES('Table'[Food]),
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "American")
) = 1 &&
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] <> "American")
) = 0
)
)
)
Count of Foods that are American and Irish (repeated values in Food Column):
DAX
CountAmericanAndIrish =
CALCULATE(
COUNTROWS(
FILTER(
VALUES('Table'[Food]),
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "American")
) > 0 &&
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "Irish")
) > 0
)
)
)
Count of Foods that are Italian:
DAX
CountItalian =
CALCULATE(
COUNTROWS(
FILTER(
VALUES('Table'[Food]),
COUNTROWS(
FILTER('Table', 'Table'[Food] = EARLIER('Table'[Food]) && 'Table'[Category] = "Italian")
) > 0
)
)
)
Proud to be a Super User! |
|
hI @bhanu_gautam @sroy_16 @danextian - Thanks for all of your help.
Can you please help with the following DAX:
I want to Count the values of food in Irish and American if 2 values are selected in the slicer (America and Irish), can you please help with this?
HI @Lauraeire_81
Please give this a try and let me know if it meets your requirements.
IrishandAmerican =
VAR selectedValues = VALUES('Sheet1'[Column1])
RETURN
IF (
COUNTROWS(selectedValues) = 2
&& "Irish" IN selectedValues
&& "American" IN selectedValues,
CALCULATE (
DISTINCTCOUNT('Sheet1'[Column2]),
'Sheet1'[Column1] IN {"Irish", "American"}
),
0
)
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 57 | |
| 44 | |
| 40 | |
| 21 | |
| 18 |