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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
nok
Helper III
Helper III

Calculate average variance

Hello!
Please note that all the columns and measures used in my report come from the same table, called "MyTable". So... I created a measure that calculates the price variance of the Items in my table, just like this:

variance = 
VAR var_Max = MAX( MyTable[Price] )
VAR var_Min = MIN( MyTable[Price] )
RETURN
    IF(
        NOT ISBLANK( var_Min ) && var_Min <> 0,
            IF(var_Max = var_Min,
                0,
                DIVIDE( var_Max, var_Min ) -1
            ),
            BLANK()       
    )

I want to create a measure similar to this one, but that calculates the average of the variance of the Item shown in my visual table. To clarify, I have separated two examples:

1st Example: in the image below, the table on the left shows the variance of the Item and the table on the right goes into more detail, showing the variance of this item for each ID (items can have different IDs).

With this new average measure, the table on the left should show the variance of 198,75%, since it would be the average of the only two IDs that exist for this Item in the table on the right (388,71/8,80 = 198,755).

nok_1-1744230219764.png

 

2nd Example: In this example, we have a special case, since a set of ID&Item had a 0% variance, so it should not be counted for the calculation of the average. With this new average measure, the table on the left should show a variance of 37,71% (since there was an ID&Item with a 0,0% variance, and zero variance should not be used in this calculation).

nok_0-1744229763170.png

So how can I create a measure similar to the one I created, but that calculates the average variance of ID&Item within the same Item, respecting these two conditions that I showed in both examples?

 

1 ACCEPTED SOLUTION

I think we have different understanding of what Variance means.

 

Variance is the expected value of the squared variation of a random variable from its mean value, in probability and statistics.  Informally, variance estimates how far a set of numbers (random) are spread out from their mean value.

The value of variance is equal to the square of standard deviation.

 

Based on your sample data here is the variance of the individual groups

 

lbendlin_0-1744479555440.png

 

If you want the average of the variance then you need to "Think like the Grand Total"  and materialize the variances for all groups.

 

lbendlin_1-1744479727994.png

 

variance = 
var a = ADDCOLUMNS(SUMMARIZECOLUMNS(MyTable[ID       ],MyTable[Item        ]),"v",CALCULATE(var.p(MyTable[Price])))
return AVERAGEX(a,[v])

 

 

View solution in original post

5 REPLIES 5
v-achippa
Community Support
Community Support

Hi @nok,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @lbendlin and @Ashish_Mathur for the prompt response.

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the super user resolved your issue?
If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

lbendlin
Super User
Super User

You cannot measure a measure directly. Either materialize it first, or create a separate measure that implements the entire business logic.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Hi, @lbendlin . Thanks for the reply!

I can't create a sample data report because I think I can't even share the sample data path in a pbix file.
But my table has this structure:

ID       Item        Price
111Pen10
111Pen10
222Pen15
222Pen17
333Pen13
333Pen5
333Rubber10
333Rubber20
444Rubber22
444Rubber19
444Rubber26


So, based on this example table, the variance by ID&Item (represented as the tables on the right in my original post) would be:

111, Pen -> (10/10) -1 = 0%
222, Pen -> (17/15) -1 = 0,13%
333, Pen -> (13/5) -1 = 1,6%

333, Rubber -> (20/20) -1 = 0%
444, Rubber -> (26/19) -1 = 0,36%

 

And based on this structure and in the variance results by ID&Item, this average measure would show this value for each Item:

Item        Variance
Pen0,86%
Rubber0,36%


Explanation: 
Pen -> (0,13% + 1,6%)/2 = 0,86% (any ID&Item that has a 0% variation should not be considered in the average calculation)
Rubber -> (0,36%)/1 = 0,36% (any ID&Item that has a 0% variation should not be considered in the average calculation)

Hi,

Your explanation is inconsistent and confusing.  For 222 why is the calculation 17/15 and for 333 as 13/5 (why not 5/13)?  Also, shouldn't there be a date column as well?


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

I think we have different understanding of what Variance means.

 

Variance is the expected value of the squared variation of a random variable from its mean value, in probability and statistics.  Informally, variance estimates how far a set of numbers (random) are spread out from their mean value.

The value of variance is equal to the square of standard deviation.

 

Based on your sample data here is the variance of the individual groups

 

lbendlin_0-1744479555440.png

 

If you want the average of the variance then you need to "Think like the Grand Total"  and materialize the variances for all groups.

 

lbendlin_1-1744479727994.png

 

variance = 
var a = ADDCOLUMNS(SUMMARIZECOLUMNS(MyTable[ID       ],MyTable[Item        ]),"v",CALCULATE(var.p(MyTable[Price])))
return AVERAGEX(a,[v])

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors