cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EZV12
Helper III
Helper III

DAX formula Distinct/Distinctcount

Dear all,

I need to calculate the total number of customers for "Estimated Sales = SALES+FIRM ORDERS+FORECAST".  I applied a formulas DAX to calculate the sum of customers of the 3 categories below, however, the output is not the distinct number of customers for the total Estimated Sales. There are duplicates.  May you please help? Thanks.

NB Customers TO+FO+Frcst =
CALCULATE(
DISTINCTCOUNT(SALES[Customer_Code])
+DISTINCTCOUNT(SALES_FIRM_ORDERS[Customer_Code])
+DISTINCTCOUNT(SALES_FORECAST[Customer_Code])
)

 

SALES FIRM ORDERS FORECAST
Customer Code Customer Code Customer Code
A A B
B B C
C E F
D F G
E G H
A B C
C F 

H

1 ACCEPTED SOLUTION
selimovd
Community Champion
Community Champion

Hey @EZV12 ,

 

you have to combine the columns first and then count the distinct values.

Try the following measure:

 

Amount Distinct Customers = 
COUNTROWS (
    DISTINCT (
        UNION (
            VALUES ( 'FIRM ORDERS'[Customer Code] ),
            VALUES ( FORECAST[Customer Code] ),
            VALUES ( SALES[Customer Code] )
        )
    )
)

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

3 REPLIES 3
selimovd
Community Champion
Community Champion

Hey @EZV12 ,

 

you have to combine the columns first and then count the distinct values.

Try the following measure:

 

Amount Distinct Customers = 
COUNTROWS (
    DISTINCT (
        UNION (
            VALUES ( 'FIRM ORDERS'[Customer Code] ),
            VALUES ( FORECAST[Customer Code] ),
            VALUES ( SALES[Customer Code] )
        )
    )
)

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

Hello Denis,

It works!!  Thank you very much for your help!

Best regards

Rachel

PaulDBrown
Super User II
Super User II

@EZV12 
Try:

Disctinct values =
VAR _Sales =
    VALUES ( 'Table'[SALES] )
VAR _FirmOrders =
    VALUES ( 'Table'[FIRM ORDERS] )
VAR _Forecast =
    VALUES ( 'Table'[FORECAST] )
RETURN
    COUNTROWS ( DISTINCT ( UNION ( _Sales, UNION ( _FirmOrders, _Forecast ) ) ) )




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Top Kudoed Authors