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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
GianPaolo
Frequent Visitor

DISTINCTCOUNT on factTable based on 2 Criteria

Hi Everyone!

 

I am quite new to DAX. I made my model really simple in the attached file .xlsx

I would like to compute a DISTINCTCOUNT of the FACT_TABLE[CUSTOMER ID] based on the following criteria:

 

Total Values for each "Customer ID" in the "1 SEMESTER" = 0 AND Total Values for each "Customer ID" in the 2 SEMESTER >  0

In this example CUSTOMER ID = 1 AND CUSTOMER ID = 3 are ok and they should be counted in the DISTINCTCOUNT because both have 1 semester = 0 and 2 semester > 0

 

https://filetransfer.io/data-package/47cqvbpL#link

 

thanks in advance

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1654549969941.png

 

For fun only, a showcase of powerful Excel worksheet formula,

CNENFRNL_1-1654550106706.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1654549969941.png

 

For fun only, a showcase of powerful Excel worksheet formula,

CNENFRNL_1-1654550106706.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank you for your answer!! Unofortunately I am using Power Pivot and the TREATAS is not provided....

I think it is really a good idea the Excel flag you did...

DO you think would be possibile to add a calculated column in the model for doing the same thing as you did in the Excel Worksheet?

Thanks a lot!

johnt75
Super User
Super User

Num customers =
var semester1 = CALCULATETABLE( VALUES('Table'[Customer ID]), 
TREATAS( { ("Semester 1", 0)}, 'Table'[Semester], 'Table'[Values Euro]) )
var semester2 = CALCULATETABLE( VALUES('Table'[Customer ID]), 'Table'[Semester] = "Semester 2" && 'Table'[Values Euro] > 0)
return DISTINCTCOUNT(UNION(semester1, semester2))

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors