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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
amikm
Helper V
Helper V

How to get distinct count of each row and sum using DAX

I need to calculate distinct count of each product (P1,P2,P3) which has sales grater than 0 and then sum and give me total Product count in a card visual. I have written a below DAX to get the count , but it is not giving me correct result.


TotalProductCount:=
SUMX (
    VALUES ( Product[Location] ),
    CALCULATE (
        DISTINCTCOUNT(  Product[ProductCode] ),
        Product[SalesAmount] > 0))

 

expected output we need as 24

amikm_0-1727681547828.png

Sales=SUM(SalesAmount)

Also, P1,P2,P3 are the Measures
P1:= CALCULATE ([Sales], KEEPFILTERS(Product[ProductCode] = "P1"))
P2:= CALCULATE ([Sales], KEEPFILTERS(Product[ProductCode] = "P2"))
P3:= CALCULATE ([Sales], KEEPFILTERS(Product[ProductCode] = "P3"))

1 ACCEPTED SOLUTION
Jpss
Resolver II
Resolver II

hello @amikm 
Your dataset has no 0 values and null values does is not same as a 0. 
so in my dataset i did not calculate values >0, but if in your dataset you expect to see 0, you can place that filter. 

The best way to handle this is to transform the table like this : 

Jpss_0-1727683172022.png

once this is done, rest ofthe calculations are simeple. 

Check out this pbix amikm_ jpssSol.pbix

 

if you find this helpful, consider marking this as a solution

View solution in original post

1 REPLY 1
Jpss
Resolver II
Resolver II

hello @amikm 
Your dataset has no 0 values and null values does is not same as a 0. 
so in my dataset i did not calculate values >0, but if in your dataset you expect to see 0, you can place that filter. 

The best way to handle this is to transform the table like this : 

Jpss_0-1727683172022.png

once this is done, rest ofthe calculations are simeple. 

Check out this pbix amikm_ jpssSol.pbix

 

if you find this helpful, consider marking this as a solution

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.