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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ManjunathaEP
Helper II
Helper II

Calculate count of orders by multiple statuses

Hi, I have sample data and requirements as mentioned below, please help me out with DAX.

Sample data

Order#Cust.NameY/N? Amount 
1ABCY             12
2XYZN             23
3HFGY             45
4DGFY           656
5FFGY             75
6ABCN             67
7XYZN             55
8YUIN             44
9KDFN             33

Requirements

1. Count of orders for the distinct customer for Y/N? = Y and N. (Result must be 4 for ABC and XYZ every 2 orders)

2. Count of orders for the distinct customer for Y/N? = Y (Result must be 3 for HFG,DGF and FFG each 1 order)

3. Count of orders for the distinct customer for Y/N? = N (Result must be 2 for YUI and KDF each 1 order)

4. Sum of row totals by customer name does not match with the column total

4 REPLIES 4
jameszhang0805
Resolver IV
Resolver IV

Based on your data source, and the requirements you described, the result should be :

jameszhang0805_0-1614424892384.png

And  4. Sum of row totals by customer name does not match with the column total
what is this mean? can you give an example?

 

Thank you for putting the table with the expected result and this is what is expected.

Requirement 4: If I get the totals correctly as shown in the result table, that would suffice. 

Thank you for this, it will be good, if I get DAX

#OrderYandN = 
VAR _TableN = CALCULATETABLE( VALUES( 'Order'[Cust.Name] ), 'Order'[Y/N?] = "N" )
VAR _TableY = CALCULATETABLE( VALUES( 'Order'[Cust.Name] ), 'Order'[Y/N?] = "Y" )
VAR _BothYandN = INTERSECT( _TableY , _TableN )
RETURN COUNTROWS( _BothYandN )

#Orders_Y = 
VAR _TableN =
CALCULATETABLE( VALUES( 'Order'[Cust.Name] ), 'Order'[Y/N?] = "N" )
VAR _TableY = EXCEPT( VALUES( 'Order'[Cust.Name] ) , _TableN )
RETURN CALCULATE( COUNTROWS( 'Order' ) , _TableY ) 

#Orders_N = 
VAR _TableY =
CALCULATETABLE( VALUES( 'Order'[Cust.Name] ), 'Order'[Y/N?] = "Y" )
VAR _TableN = EXCEPT( VALUES( 'Order'[Cust.Name] ) , _TableY )
RETURN CALCULATE( COUNTROWS( 'Order' ) , _TableN )  

Hi, Thank you for the reply but the given DAX is calculating the "customer count" instead of the "order count". I expected the order count from the table. It will be good, If I get DAX to calculate distinct order count from given sample data.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors