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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
nok
Advocate II
Advocate II

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.