Forum Discussion

nok's avatar
nok
Icon for Advocate II rankAdvocate II
1 year ago
Solved

Average variance by Item

Hello! My table has this structure: ID        Item         Price 111 Pen 10 111 Pen 10 222 Pen 15 222 Pen 17 333 Pen 13 333 Pen 5 333 Rubber 10 333 Rubbe...
  • andrewsommer's avatar
    1 year ago

    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.