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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
KyleTaylor
Advocate I
Advocate I

DAX measure to count customers with multiple sizes in each order per day

Hi,

 

Please help! I need a DAX measure to count the numbe of customers per order per day with multiple sizes in the order?

 

With the sample below, I would except the following:

Jan with 1 customer with multiple sizes in the order

Feb with 2 customers with multiple sizes in the order (Customer 222 is ignored because only 1 size in order)

 

I have tried COUNTROWS( Sales) and

 

COUNTROWS( DISTINCT( Sales[Size])) and

 

COUNTROWS (
  EXCEPT (
    VALUES ( Sales[Customer ID] ),
    SUMMARIZE (
      GENERATE (
      VALUES ( Sales[CustomerID] ),
      EXCEPT (
    VALUES ( Sales[Size] ),
    CALCULATETABLE ( VALUES ( Sales[Size] ) )
     )
    ),
  Sales[Customer ID]
  )
)
)

 

Any ideas?

 

DateCustomer IDOrder IDSize
1-Jan123ABC-10010
1-Jan123ABC-10012
3-Feb123ABC-11812
3-Feb123ABC-11814
7-Feb222ABC-22610
9-Feb125ABC-2348
10-Feb125ABC-23410
4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Screenshot 2021-06-22 120254.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!

Thanks, that worked as expected! What if I want to add another field to the table/measure? When I add a field after Customer ID the table goes blank? Same with [Size], could that be added to the table? It goes blank when I do.

 

# Multi Sizes =
VAR __grp =
ADDCOLUMNS (
SUMMARIZE ( ORDERS, ORDERS[Order ID], ORDERS[Customer ID], ORDERS[Type] ),
"@count", CALCULATE( DISTINCTCOUNT( ORDERS[Size] ) )
)
RETURN
COUNTROWS ( FILTER( __grp, [@count] > 1 ) )

 

I have a field called TYPE that I want to include. The result would be:

 

YYYYMMType# Multi Sizes
2021-01Dress1
2021-02Dress1
2021-02Top1

 

Data:

 

DateCustomer IDOrder IDSizeType
1-Jan123ABC-10010Dress
1-Jan123ABC-10012Dress
3-Feb123ABC-11812Dress
3-Feb123ABC-11814Dress
7-Feb222ABC-22610Pants
9-Feb125ABC-2348Top
10-Feb125ABC-23410Top
Jihwan_Kim
Super User
Super User

 

Picture1.png

 

Customers count multiple orders : =
IF (
ISFILTERED ( Dates[Month Name] ),
COUNTROWS (
SUMMARIZE (
FILTER (
ADDCOLUMNS (
SUMMARIZE ( Data, Dates[Month Name], Customers[Customer ID], Data[Order ID] ),
"@countorders", CALCULATE ( COUNTROWS ( VALUES ( Data[Size] ) ) )
),
[@countorders] > 1
),
Customers[Customer ID]
)
)
)
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thanks, that worked as expected! I notice there is no total on this measure? Is there a way to add a total (3 in this case)?

 

What if I want to add another field to the table/measure? When I add a field after Customer ID the table goes blank? Same with [Size], could that be added to the table? It goes blank when I do.

 

Customers count multiple orders : =
IF (
ISFILTERED ( Dates[Month Name] ),
COUNTROWS (
SUMMARIZE (
FILTER (
ADDCOLUMNS (
SUMMARIZE ( Data, Dates[Month Name], Customers[Customer ID], Data[Order ID], Data[Type] ),
"@countorders", CALCULATE ( COUNTROWS ( VALUES ( Data[Size] ) ) )
),
[@countorders] > 1
),
Customers[Customer ID]
)
)
)

 

I have a field called TYPE that I want to include. The result would be:

 

YYYYMMType# Multi Sizes
2021-01Dress1
2021-02Dress1
2021-02Top1

 

Data:

 

DateCustomer IDOrder IDSizeType
1-Jan123ABC-10010Dress
1-Jan123ABC-10012Dress
3-Feb123ABC-11812Dress
3-Feb123ABC-11814Dress
7-Feb222ABC-22610Pants
9-Feb125ABC-2348Top
10-Feb125ABC-23410Top

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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!