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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
psmith-nhs-inc
Helper III
Helper III

How to do a count of a count?

OK, pretty simple question, I think.  I have customers.  They have invoices. Using Slicers, I can choose a customer, and show many invoices they have, or build a matrix to show each customer and how many thay have each.

I can choose a date range, and show how many total invoices were shipped within that range, with a matrix by customer.

 

What I want to show, however is how many customers ordered exactly 5 times, how many ordered exactly 4 times, how many ordered exactly three times, etc. within that date range.

 

I am not sure quite how to go about this in DAX.  I can get specific if I need to, but I think just the general concept would be enough to get me where I need to be.

 

Thank for any assistance.

 

Phil

 

 

1 ACCEPTED SOLUTION

Hi @psmith-nhs-inc

 

Try this Calculated Table

 

from the Modelling tab >>New Table

 

Table =
SUMMARIZE (
    SUMMARIZE (
        CustomerTable,
        CustomerTable[Customer Name],
        "Order_Count", COUNTROWS ( InvoiceTable )
    ),
    [Order_Count],
    "Count of Customers with", COUNT ( CustomerTable[Customer Name] )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

 

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

 

InvoiceTable 
Invoice#Customer# Invoice Amount 
10014 $                637.97
10023 $                456.71
10031 $                619.04
10041 $                992.96
10053 $                987.20
10064 $                194.08
10074 $                  35.97
10081 $                479.84
10091 $                929.18
10102 $                271.85
10113 $                288.53
10121 $                219.49

 

CustomerTable
Customer #Customer Name
1Joe
2Fred
3Mark
4Nathan

 

With this DAX: Orders_Count = Calculate(DISTINCTCOUNT(InvoiceTable[invoice#]))

I can get this result:

Customer Name Order_Count 
Joe5
Fred1
Mark3
Joe3

Now I want the Next Level:

Count_Of_Customers_WithOrder_Count
11
23
1

5

If I know how to count the count, I should be able to figure out how to Slice and sort by count.  For instance, Customer with most orders on top.  Customers with 100 orders.

 

I am trying to wrap my head around the suggestion offered in the previous post.  It is not quite gelling for me.

 

Thanx for any help.

Hi @psmith-nhs-inc

 

Try this Calculated Table

 

from the Modelling tab >>New Table

 

Table =
SUMMARIZE (
    SUMMARIZE (
        CustomerTable,
        CustomerTable[Customer Name],
        "Order_Count", COUNTROWS ( InvoiceTable )
    ),
    [Order_Count],
    "Count of Customers with", COUNT ( CustomerTable[Customer Name] )
)

Regards
Zubair

Please try my custom visuals

Thank you.  I was able to adapt that to my PBIX, and now I understand how Summarize works.  Previous explanations were a little too generic to wrap my head around.

 

Thank You.

@psmith-nhs-inc

 

See file attached here.

It works with the sample data

 

CountofaCount.png


Regards
Zubair

Please try my custom visuals
Greg_Deckler
Super User
Super User

This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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