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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
nok
Helper III
Helper III

Average variance by Item

Hello!
My table has this structure:

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


I have already created a measure that calculates variance by ID&Item. So, based on this example table, the variance by ID&Item 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 variance results by ID&Item, I want to create now a measure that calculates the average of each variance per item. The expected result of this new measure would be this:

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)

I'm having trouble creating this measure that averages variance per item. How can I do this?

1 ACCEPTED SOLUTION
andrewsommer
Super User
Super User

Should be a simple two step process. 

 

Create a calculated table of unique ID-Item combinations with their variance

VariancePerIDItem = 
ADDCOLUMNS (
    SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[Item] ),
    "Variance", 
        VAR Prices = 
            CALCULATETABLE (
                VALUES('Table'[Price]),
                ALLEXCEPT('Table', 'Table'[ID], 'Table'[Item])
            )
        RETURN 
            DIVIDE ( MAXX(Prices, [Price]), MINX(Prices, [Price]) ) - 1
)

 

Then, create a measure that calculates the average of non-zero variances per item:

AverageVariancePerItem = 
AVERAGEX (
    FILTER (
        VariancePerIDItem,
        [Variance] <> 0
            && VariancePerIDItem[Item] = SELECTEDVALUE('Table'[Item])
    ),
    [Variance]
)

When you place Item in your visual and use this [AverageVariancePerItem] measure, you’ll get your expected result.

 

Please mark this post as solution if it helps you. Appreciate Kudos.

View solution in original post

1 REPLY 1
andrewsommer
Super User
Super User

Should be a simple two step process. 

 

Create a calculated table of unique ID-Item combinations with their variance

VariancePerIDItem = 
ADDCOLUMNS (
    SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[Item] ),
    "Variance", 
        VAR Prices = 
            CALCULATETABLE (
                VALUES('Table'[Price]),
                ALLEXCEPT('Table', 'Table'[ID], 'Table'[Item])
            )
        RETURN 
            DIVIDE ( MAXX(Prices, [Price]), MINX(Prices, [Price]) ) - 1
)

 

Then, create a measure that calculates the average of non-zero variances per item:

AverageVariancePerItem = 
AVERAGEX (
    FILTER (
        VariancePerIDItem,
        [Variance] <> 0
            && VariancePerIDItem[Item] = SELECTEDVALUE('Table'[Item])
    ),
    [Variance]
)

When you place Item in your visual and use this [AverageVariancePerItem] measure, you’ll get your expected result.

 

Please mark this post as solution if it helps you. Appreciate Kudos.

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.