Forum Discussion

NOVICE02's avatar
NOVICE02
Helper III
4 years ago
Solved

Calculating Weighted average from transactional data

Hi all, 

This is a first for me. I have looked at the other solutions and still can't figure it out.

 

I have transactiona data like below (note there are 20+ variables). I need to calculate the weighted average of the balance and i want to show it for different segment types if possible... ie. by class or by month & class and so forth

 

 

IDClassBalanceDate
1mm733.662021-11-02
2h1742.482021-11-02
3ll726.652021-11-02
4lr680.052021-11-02
5ll1405.362021-11-02
6mr904.082021-11-02
7ml387.542021-11-02
8h549.252021-11-02
9hl1124.72021-11-02
10hr444.312021-11-02

 

What would be the best way to approach this ? Appreciate any direction on this frequently discussed topic

  • To calculate the weighted average according to different segment types, you may need to create multiple measures.

    The measure I created is calculated according to class.

    WA Sales by Product = 
    VAR AnnualSales =
        CALCULATE(
            SUM('Table (2)'[Balance]),
            ALL('Table (2)'[Class])
        )
    VAR SummarisedTable =
        ADDCOLUMNS(
            SUMMARIZE(
                'Table (2)','Table (2)'[Class],'Table (2)'[Date].[Year]
                
            ),
            "SalesWt", SUM('Table (2)'[Balance]) / AnnualSales,
            "Sales", SUM('Table (2)'[Balance])
        )
    RETURN
        SUMX(
            SummarisedTable,
            [SalesWt] * [Sales]
        )

     

2 Replies

  • NOVICE02 , What is the expected value.

     

    You can try a measure like

    divide(sum(Table[Balance]), count(Table[Balance]))

  • V-lianl-msft's avatar
    V-lianl-msft
    Community Support

    To calculate the weighted average according to different segment types, you may need to create multiple measures.

    The measure I created is calculated according to class.

    WA Sales by Product = 
    VAR AnnualSales =
        CALCULATE(
            SUM('Table (2)'[Balance]),
            ALL('Table (2)'[Class])
        )
    VAR SummarisedTable =
        ADDCOLUMNS(
            SUMMARIZE(
                'Table (2)','Table (2)'[Class],'Table (2)'[Date].[Year]
                
            ),
            "SalesWt", SUM('Table (2)'[Balance]) / AnnualSales,
            "Sales", SUM('Table (2)'[Balance])
        )
    RETURN
        SUMX(
            SummarisedTable,
            [SalesWt] * [Sales]
        )