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
freddiec03
Helper I
Helper I

Calculating an average of an average

I am trying to find an average per user based off an average measure from two columns. Here is some sample data. This table made up of data from multiple tables. The table below it is the expected output I would like to see. Whenever I attempt this im just using the same measure for (Average Accuracry) as the same as (accuracry). The measure below works for the initial table but for the end game it appears that its taking the sum of all the prices paid divided by the sum of all the highs set and giving a much high % 

 

Accuracy (%) = if(ISBLANK(max(table[high])),BLANK(),sum(Total[Paid])/max(table[high]))

 

Main Table
   *measure 
ItemPaidHighAccuracyHigh Setter
a2367%Bob
b33100%Steve
c54125%Jim
d5683%Bob
e22100%Lisa
f3475%Steve
g54125%Jim
h44100%Jim
i4580%Steve
j2367%Bob
k11100%Lisa

 

Output
High SetterAverage  Accuracy
Bob72.30%
Steve85%
Jim116.67%
Lisa100%
1 ACCEPTED SOLUTION

Accuracy =
VAR a =
    ADDCOLUMNS(
        VALUES( 'Change Log'[ID] ),
        "HD",
            VAR mxid = [ID]
            RETURN
                CALCULATE(
                    MAX( 'Change Log'[Date] ),
                    REMOVEFILTERS( 'Change Log'[Name] ),
                    'Change Log'[ID] = mxid
                ),
        "HS",
            VAR mxid = [ID]
            VAR mxd =
                CALCULATE(
                    MAX( 'Change Log'[Date] ),
                    REMOVEFILTERS( 'Change Log'[Name] ),
                    'Change Log'[ID] = mxid
                )
            RETURN
                CALCULATE(
                    MAX( 'Change Log'[Name] ),
                    ALLSELECTED( 'Change Log' ),
                    'Change Log'[ID] = mxid,
                    'Change Log'[Date] = mxd
                ),
        "HV",
            VAR mxid = [ID]
            VAR mxd =
                CALCULATE(
                    MAX( 'Change Log'[Date] ),
                    REMOVEFILTERS( 'Change Log'[Name] ),
                    'Change Log'[ID] = mxid
                )
            RETURN
                CALCULATE(
                    SUM( 'Change Log'[High] ),
                    ALLSELECTED( 'Change Log' ),
                    'Change Log'[ID] = mxid,
                    'Change Log'[Date] = mxd
                ),
        "PDT",
            VAR mxid = [ID]
            RETURN
                CALCULATE( SUM( 'Payment Details'[Total] ), 'Payment Details'[ID] = mxid )
    )
VAR b =
    FILTER( a, [HS] = MAX( 'Change Log'[Name] ) )
RETURN
    AVERAGEX( b, DIVIDE( [HV], [PDT], 0 ) )

View solution in original post

23 REPLIES 23
Greg_Deckler
Super User
Super User

@freddiec03 It's either one of these two solutions but I can't be sure which:

First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8

 

or:

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

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.


@ 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...
grantsamborn
Solution Sage
Solution Sage

Hi @freddiec03 

Have you considered using a calculated table?  (or is that cheating?)

 

/********** Measure **********/
Accuracy (%) = 
IF(
    ISBLANK( MAX( 'Table'[High] ) ),
    BLANK(),
    SUM( 'Table'[Paid] )
        / MAX( 'Table'[High] )
)

/********** Calculated Table */
zSummary = 
SUMMARIZECOLUMNS(
    'Table'[Item],
    'Table'[High Setter],
    "Accuracy", [Accuracy (%)]
)

/********** Measure **********/
zAvg = 
AVERAGEX(
    FILTER(
        ALL( 'zSummary' ),
        'zSummary'[High Setter] = SELECTEDVALUE( zSummary[High Setter] )
    ),
    [Accuracy]
)

 

pbix: Average_of_an_Average.pbix

 

 

So I actually did a bad job at explaining this.... in your item column the goal is to have a unique item ID but whenever I bring over the High data there is multiple highs for each item... I want to just look at the most recent high submission. (there is a datetime column to create a measure if needed just not sure how to proceed)

Hi @freddiec03 

Is there any way you could come up with a pbix with sample data?

Grant

Average of an Average 

 

first time posting a pbix file on here so let me know. One not to add is on the Date column that the format is DateTime and has times inserted as well in the same column. Just simplified the data as easy as possible for you though. The way the table is set up is how I have tried connecting 3 different data sets. I created one measure for Accuracy % as well. Let me know your thoughts or if you have any questions! Thanks!

Hi @freddiec03 

Are these your expected results?

Bob156.07
Dan157.59
Jill103.41
Jim135.53

I would like to see the final two tables to look like the ones below. I only want to show the most recent high based off date and for the user average I would like it to only calculate for the ones represented in the table not for everyone that has inputed a high (as you can see in the pbix that multiple ppl have submitted a high but the table will only reflect the latest submission)

 

IDCompanyTotal (Paid)HighChange AccuracyName (High Setter)DateManager
1Sheetz109111%Dan1/14/2023Lisa
2McDonalds7887.50%Bob1/15/2023Steve
3Arby86133%Jim1/18/2023Wes
4Wendys6785.71%Dan1/26/2023Jess
5Subway98112.50%JIm1/16/2023Mike
6Walmart86133.33%JIm1/22/2023Ken
7Chick Fila107142.86%Jim1/22/2023Bill

 

High SetterAccuracy
Dan98%
Bob87.50%
Jim131%

Hi @freddiec03 

I'm not having much luck at this.  (tried changing relationships, "average of average" pattern...)

 

Maybe you should call in some of the big-guns...

@amitchandak 

@lbendlin 

@Ashish_Mathur 

@Idrissshatila 

@Greg_Deckler 

 

 

Just cannot understand your question.  Explain the expected result in detail. 


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

Hi @Ashish_Mathur 

I sent Freddie a msg on the side for clarification.  These seem to be the required steps.

 

1. For each company, filter out all records except for the latest for that company to find [Setter] (employee).
2. For each record in the result set, calculate [Change Accuracy %].
3. For each employee in the result set, calculate an average of that employee's [Change Accuracy %] amounts.

 

(as you can see in the pbix that multiple ppl have submitted a high but the table will only reflect the latest submission)

 

That is an assumption bordering on a fallacy.  How can you guarantee that each company has at least one entry in the change log?  What should be done if there are two changes for the same company and date?

 

Please let me know why the sum total in my version doesn't match your sample.

 

For the second deliverable  I would change the perspective and iterate through the list of names, check if they are high setter for any of the companies, and then apply the averagex.

for the question on what if a high is submitted on the same day the format and data I am pulling is pulling DateTime so we have a time aspect as well... in my example I just used a simplified version of the data

Accuracy =
VAR a =
    ADDCOLUMNS(
        VALUES( 'Change Log'[ID] ),
        "HD",
            VAR mxid = [ID]
            RETURN
                CALCULATE(
                    MAX( 'Change Log'[Date] ),
                    REMOVEFILTERS( 'Change Log'[Name] ),
                    'Change Log'[ID] = mxid
                ),
        "HS",
            VAR mxid = [ID]
            VAR mxd =
                CALCULATE(
                    MAX( 'Change Log'[Date] ),
                    REMOVEFILTERS( 'Change Log'[Name] ),
                    'Change Log'[ID] = mxid
                )
            RETURN
                CALCULATE(
                    MAX( 'Change Log'[Name] ),
                    ALLSELECTED( 'Change Log' ),
                    'Change Log'[ID] = mxid,
                    'Change Log'[Date] = mxd
                ),
        "HV",
            VAR mxid = [ID]
            VAR mxd =
                CALCULATE(
                    MAX( 'Change Log'[Date] ),
                    REMOVEFILTERS( 'Change Log'[Name] ),
                    'Change Log'[ID] = mxid
                )
            RETURN
                CALCULATE(
                    SUM( 'Change Log'[High] ),
                    ALLSELECTED( 'Change Log' ),
                    'Change Log'[ID] = mxid,
                    'Change Log'[Date] = mxd
                ),
        "PDT",
            VAR mxid = [ID]
            RETURN
                CALCULATE( SUM( 'Payment Details'[Total] ), 'Payment Details'[ID] = mxid )
    )
VAR b =
    FILTER( a, [HS] = MAX( 'Change Log'[Name] ) )
RETURN
    AVERAGEX( b, DIVIDE( [HV], [PDT], 0 ) )

This gets me very close to where I need to be but the biggest problem I am seeing is for the PDT column it is returning a calculated value rather than a data point that was set. The return values of 17,12,15,10 arent values that were submitted by the High setters.

 

freddiec03_0-1675189707666.png

 

Please see my question further up.

I cannot understand.  Someone else who does will help.  Sorry.


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

Hi @freddiec03 

I took a look at your model and am trying a couple of other methods but with no luck yet.

(The model has changed quite a bit.)

I'll let you know if I have any luck.

Yea apoligies as I didnt do to well explianing to begin with as some data is sensitive to share.... new to the forums here so if theres anything else you need please let me know

When creating a calculate table Im getting an error shot back at me "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

Hi @freddiec03 

Have you checked the pbix that I attached?  

This might seem like a simple question but...  Are you sure you created a Calculated Table, not a Calculated Column?  the error you describe appears in that case.

 

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.