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
YcnanPowerBI
Helper II
Helper II

Using DISTINCTCOUNT measure to determine avg of another field

Hello all,

 

I have this measure to calculate the number of distinct orders that have a beverage.  I need to now also average the field Merge1[subtotal] subtotal of those orders that have a beverage, but nothing I try is working.  Appreciate any help

 

Bev Disctinct Cust = CALCULATE(DISTINCTCOUNT(Merge1[orderId]), FILTER(Merge1,Merge1[POS Data.GroupName] = "Beverage"))

 

Sample Data

 

orderIdPOS Data.GroupNamesubTotal
004BHGPizza14.76
004BHGBeverage14.76
0FZGTBSide Orders4.24
0FZGTBSide Orders4.24
066P6IPizza58.41
066P6IBeverage58.41
066P6IPizza58.41
066P6IPizza58.41
066P6ISide Orders58.41
0FZGTBSide Orders4.24
0APOCVWings35.34
0APOCVPizza35.34
1 ACCEPTED SOLUTION

Hi,

This measure works

Measure = AVERAGEX(SUMMARIZE(FILTER(Data,Data[POS Data.GroupName]="Beverage"),Data[orderId],"A",MIN(Data[subTotal])),[A])

Hope this helps.

Ashish_Mathur_0-1713412853518.png

 


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

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

Show the expected result.


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

I apologize, I forgot to include the expected result.  I also added another order to more clearly identify the expected result.  Although there are 4 beverages on the last order, it should only use one of the 1.51 subtotals in the average

 

orderIdPOS Data.GroupNamesubTotal
004BHGPizza14.76
004BHGBeverage14.76
0FZGTBSide Orders4.24
0FZGTBSide Orders4.24
066P6IPizza58.41
066P6IBeverage58.41
066P6IPizza58.41
066P6IPizza58.41
066P6ISide Orders58.41
0FZGTBSide Orders4.24
0APOCVWings35.34
0APOCVPizza35.34
0APOC8Beverage1.51
0APOC8Beverage1.51
0APOC8Beverage1.51
0APOC8Beverage1.51
 Expected Average Result24.89

Hi,

This measure works

Measure = AVERAGEX(SUMMARIZE(FILTER(Data,Data[POS Data.GroupName]="Beverage"),Data[orderId],"A",MIN(Data[subTotal])),[A])

Hope this helps.

Ashish_Mathur_0-1713412853518.png

 


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

Thank you so much!  It worked.  Would you mind explaining what this part of the measure is doing? 

"A",MIN(Data[subTotal])),[A])

 

You are welcome.  Read up on the SUMMARIZE() function.


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

Thank you!

jgeddes
Super User
Super User

Try this measure...

Average Subtotal Beverage Orders = 
AVERAGEX(
    FILTER(sampleTable, sampleTable[POS Data.GroupName] = "Beverage"),
    sampleTable[subTotal]
)



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





It does not appear to be taking the distinct order ID into consideration and instead averaging all the lines with beverage within the order.  So if an order has 2 beverages, it is looking at that subtotal as two seperate subtotals to average.

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.