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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Weighted Average

Hello, 

I need to compute a weighted average for the consumer price. 

Lorenzo_98_0-1625219947885.png

Currently, CP YTD is computed as Average(DB(consumer price). However, if I use this formula I receive an arithmetic average. 

I need to weigh the consumer price for NES YTD (Sales). 

the formula needs to be something like: (CP YTD*NES YTD)/sum(NES YTD). however, I need to do that for each level.

for example:
for liv6 [(NES Ytd 541... * CP YTD 541... )/ sum (NES YTD 541... + NES YTD 541... and so on) ]

the denominator needs to be dynamically adjusted depending on the level that is analysed. 

 

How can I do that in DAX? 

 

Thanks for the help

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Try to use the sumx function.

WA = 
VAR total_ = 
    CALCULATE(
        [NES YTD],
        ALL(xxxxx)
    )
VAR _Table = 
    ADDCOLUMNS(
        SUMMARIZE(
            Sales,
            xxx[Row1],xxx[Row2]
        ),
        "nes", [NES YTD],
        "cp", [CP YTD]
    )
RETURN
    SUMX(
        _Table ,
        [cp] * [nes]/total_
    )

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thanks for your reply! 

I have just some further questions?

 

  1. What do you mean with xxx?
    In Var total_ do I need to insert the name of the table? 
  2. in Var _Table is sales a new or existing table? 

  3. What do Row1 and Row2 refer to? 

I really appreciate your help! 

 

 

 

 

 

It refers to the column name of row labels. If the problem still exists, Please provide some sample data, preferably a pbix after removing sensitive data.

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-... 

V-lianl-msft
Community Support
Community Support

Try to use the sumx function.

WA = 
VAR total_ = 
    CALCULATE(
        [NES YTD],
        ALL(xxxxx)
    )
VAR _Table = 
    ADDCOLUMNS(
        SUMMARIZE(
            Sales,
            xxx[Row1],xxx[Row2]
        ),
        "nes", [NES YTD],
        "cp", [CP YTD]
    )
RETURN
    SUMX(
        _Table ,
        [cp] * [nes]/total_
    )

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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