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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
V1R0S
New Member

Need help with dynamic weighted average

Hi all, 


Im fairly new to PowerBI and been trying to create a Dax measure to calculate weighted average DPO.

 

Exemplary table:

Payment Days     Value     

60                        1000

60                        2000

50                        1500

30                        3500

30                         500

There are also different categories of materials and different regions, hence I want to to be reacting dynamically based on applied filters. 
First, it should build the sum of value per Payment Day
i.e. 60 days with overall 3000, 30 with 4000 etc.

OR divides the value by the sum of values to obtain the weight factor. Ultimately multiplying weight factor with Payment Day and then summing up all weighted average days to receive the overall weighted average days.


Based on a video ive watched on YT ive tried to apply formulas already. It reacts dynamically, just dont know if the values are correct. Can you maybe quickly check the code?

AverageDays =
var DTP =
SUMMARIZE(
    'Report',
    'Report'[PaymentDays],
    "ValuePerPT",
    SUMX('Report', 'Report'[Value(GC)])
)
    var DTP2 =
    ADDCOLUMNS(DTP,
    "Weight", DIVIDE(
[ValuePerPT],
SUMX(DTP, [ValuePerPT])
    )
    )
    var DTP3 =
    ADDCOLUMNS(DTP2, "WTDTP", [Weight] * 'Report'[PaymentDays])

    Return SUMX(DTP3, [WTDTP])




Thank you very much!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @V1R0S 

 

Please try this:

MEASURE =
VAR _DTP =
    FILTER (
        SUMMARIZE (
            'Report',
            'Report'[PaymentDays],
            "ValuePerPT", SUM ( Report[Value] )
        ),
        'Report'[PaymentDays] <> BLANK ()
    )
VAR _DTP2 =
    ADDCOLUMNS (
        _DTP,
        "Weight", DIVIDE ( [ValuePerPT], SUMX ( _DTP, [ValuePerPT] ) )
    )
VAR _DTP3 =
    ADDCOLUMNS ( _DTP2, "WTDTP", [Weight] * 'Report'[PaymentDays] )
RETURN
    SUMX ( _DTP3, [WTDTP] )

You can use the filter() function to filter the DTP to exclude the blank:

vzhengdxumsft_0-1720160710888.png

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V1R0S
New Member

Thank you for this. How can I use a filter here? In my original file I have rows, that have a value but a blank "payment day" cell.

 

So, back to my example:

Payment Days     Value     

60                        1000

60                        2000

50                        1500

30                        3500

                            5000

30                         500

 

I want it to ignore the blank line item and the 5000 value. (Only blanks should not be counted, "0" values must not be excluded), so basically start with a filter operation (like Filter(List,NOT ISBLANK Payment Days)) before it processes the average days function

Anonymous
Not applicable

Hi @V1R0S 

 

Please try this:

MEASURE =
VAR _DTP =
    FILTER (
        SUMMARIZE (
            'Report',
            'Report'[PaymentDays],
            "ValuePerPT", SUM ( Report[Value] )
        ),
        'Report'[PaymentDays] <> BLANK ()
    )
VAR _DTP2 =
    ADDCOLUMNS (
        _DTP,
        "Weight", DIVIDE ( [ValuePerPT], SUMX ( _DTP, [ValuePerPT] ) )
    )
VAR _DTP3 =
    ADDCOLUMNS ( _DTP2, "WTDTP", [Weight] * 'Report'[PaymentDays] )
RETURN
    SUMX ( _DTP3, [WTDTP] )

You can use the filter() function to filter the DTP to exclude the blank:

vzhengdxumsft_0-1720160710888.png

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1719507426912.png

 

 

average days: =
DIVIDE (
    SUMX ( Report, Report[Payment Days] * Report[Value] ),
    SUMX ( Report, Report[Value] )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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