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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
nok
Helper II
Helper 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
Memorable Member
Memorable Member

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
Memorable Member
Memorable Member

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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