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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Burak83_
Regular Visitor

Count based on multiple criteria DAX

Hi Gents,

I would like to count distinct values based on the combination of multiple columns.(In sample Location+Item+Status) I added my table as data model to count distinct values but it does not give correct results. I know how to distinct count using helper column or excel function like =IF(COUNTIFS($C$2:C2,C2,$B$2:B2,B2)>1,0,1)but is there any way to do it in power pivot ? as calculated column or measure? Thanks for your help and comments.

LocationItemStatusDistinct Count
KitchenPlatesMoved
1​
KitchenSpoonsStayed
1​
SaloonTVMoved
1​
SaloonChairMoved
2​
SaloonChairMoved
2​
BathroomMirrorStayed
1​

 

4 REPLIES 4
FreemanZ
Super User
Super User

hi @Burak83_ 

Try to plot a table visual with columns:Location, Item, Status, and a measure like:
Distinct Count = COUNTROWS(TableName)
 
in case of issue, could you provide some sample data?
edhans
Super User
Super User

This code does it. 

edhans_0-1679704611387.png

Distinct Count 2 = 
VAR varItems = SELECTEDVALUE('Table'[Item])
VAR varLocation = SELECTEDVALUE('Table'[Location])
VAR varStatus = SELECTEDVALUE('Table'[Status])
VAR varFilteredTable =
        CALCULATETABLE(
            'Table',
            'Table'[Item] = varItems
                && 'Table'[Location] = varLocation
                && 'Table'[Status] = varStatus
        )
VAR Result = COUNTROWS(varFilteredTable)
RETURN 
    Result


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!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hi Edhans,

Thanks for the solution. However, since I am using powerpivot it does not support selectedvalue. Is there any other equivalent formula that I can use? like IF(HASONEVALUE(<columnName>), VALUES(<columnName>), <alternateResult>)

Yes. Just use this instead of SELECTEDVALUE() in PowerPivot. It gives the same results.

 

IF ( HASONEVALUE( <columnName> ), VALUES( <columnName> ), <alternateResult> )

The first one would be:

IF ( HASONEVALUE( Table[Item] ), VALUES( Table[Item] ) )

Note that SELECTEDVALUE is coming to PowerPivot. See New DAX Functions in Excel Data Models and Power Pivot (office.com)



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!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.