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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Group by Customer - DAX Measure

Hi guys,

 

as I already got great help, I hope that you can quickly help me out regarding following issue.

 

I have a table with 2 Customers and several purchasements. We have the customerID, the amount and the Number of Purchase (i.e. first purchase = 1, second purchase = 2 etc.).

 

CustomerAmountNumber of PrchaseAvgAmountPerPurchaseAvgAmountPerPurchasePerCustomer
A20032001287,5
A10022001287,5
A30012001287,5
B500423751287,5
B1000323751287,5
B3000223751287,5
B5000123751287,5

 

I need first to calculate the AvgAmount of Purchase i.e. SUM of the Amount divided by the distinct count of purchases per customer.

 

Example A: (200+100+300) = 600 / 3 Purchases = 200

Example B: (500+1000+3000+5000) = 9500 / 4 Purchases = 2375

 

In the end I need to sum the AvgPurchase Amount per customer and divide by number of customers:

= 200 + 2375 = 2575 / 2 Customer (Customer A and B) = 1287,5 

 

The result 1287.5 should be the result of the measure.

 

I am able to calculate AvgAmount Purchase in case when I put the customer on a column but I am loosing the row context (I hope the wording is correct) once I remove the customer column as I get the SUM of Amount divided by the overall distinctcount of "number of purchase"

 

 

DIVIDE(SUM(A[Amount),DISTINCTCOUNT(A[NumbeOfPurchases))

 

I need a way to use somekind of a group by but I can't figure out since hours how to do it.

 

I hope it's somehow clear. Thanks in advance.

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous

 

Try this for your measure. You can set it in a Card visual, for instance.

 

TotalAverage =
AVERAGEX (
    ADDCOLUMNS (
        VALUES ( Table1[Customer] );
        "AvgPerCustomer"; DIVIDE (
            CALCULATE ( SUM ( Table1[Amount] ) );
            CALCULATE ( COUNT ( Table1[Amount] ) )
        )
    );
    [AvgPerCustomer]
)

 

Code formatted with   www.daxformatter.com

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @Anonymous

 

Try this for your measure. You can set it in a Card visual, for instance.

 

TotalAverage =
AVERAGEX (
    ADDCOLUMNS (
        VALUES ( Table1[Customer] );
        "AvgPerCustomer"; DIVIDE (
            CALCULATE ( SUM ( Table1[Amount] ) );
            CALCULATE ( COUNT ( Table1[Amount] ) )
        )
    );
    [AvgPerCustomer]
)

 

Code formatted with   www.daxformatter.com

Anonymous
Not applicable

@AlB

 

Thanks for the solution - a little modification was required but worked. thanks.

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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