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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
aloosh89
Helper I
Helper I

How to count distinct occurences of one variable for each distinct value of another variable

Hello,

 

New to writing DAX code and I have been stuck with this. I beleive it is simple as I can do it quickly with a for loop but in DAX not sure how to go about it.

 

Below is a sample table. The last column is not part of the data but an indicator of what gets counted.

 

I would like to count for each Asset Name the unique occurences of Asset Feature under a filter of Asset Environment  = 'Cold'.

 

The desired result should be a count of 4.

 

Asset Name    

Asset

Feature

Asset EnvironmentDesired Outcome from counting function
Asset1xColdGets counted
Asset1xColdDoes not get counted since value 'x' occurs previously for this asset
Asset1zColdGets counted
Asset2yColdGets counted
Asset2xColdGets counted even though 'x' exists in Asset 1. 
Asset3wHotDoes not get counted due to 'Hot' environment

 

Thanks in advance!

Ali 

1 ACCEPTED SOLUTION
LuizKoller
Resolver I
Resolver I

Hello!

 

Measure = 

VAR TableData = 
SUMMARIZE(
    FILTER(
        'TableName',
        TableName[Asset Environment] = "Cold"
    ),
    'TableName'[Asset Name],
    'TableName'[Asset Feature]
)

RETURN
COUNTROWS(TableData)

View solution in original post

4 REPLIES 4
LuizKoller
Resolver I
Resolver I

Hello!

 

Measure = 

VAR TableData = 
SUMMARIZE(
    FILTER(
        'TableName',
        TableName[Asset Environment] = "Cold"
    ),
    'TableName'[Asset Name],
    'TableName'[Asset Feature]
)

RETURN
COUNTROWS(TableData)

Hello Again,

 

The solution works but I found an added layer of complexity when I went to implement on the actual data model I have.

 

My fact table (let's calll it Fact_Table) has the columns "Asset Feature" and "Asset Environment" but does not have the "Asset Name" column. Fact_Table also has a column "Activity_ID". 

 

The Fact_Table is linked in the data model to another table (let's call it Activity_Table). Activity_Table has a one to many relationship with FACT_Table with primary key being “Activity_ID”. 

 

Finally Activity_Table is linked to a third table (let’s call it Asset_Table). Activity_Table has a one to many relationship with Asset_Table with primary key being “Activity_ID” as well. In this Activity_Table is where the “Asset Name” is which is required for the counting as per my initial sample table.

I believe since the intermediate table Activity Table links the Fact_Table with the Asset_Table using that same “Activity_ID”, I should be able to modify the DAX code to achieve the desired result but it probably requires embedding yet another nested summarize or something of that sort.

Would be grateful if there is a solution!

 

Thanks

Ali

Can you please provide example data?

 

I tried to replicate the database as explained, but I got confused with the Activity ID

Thanks so much!

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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