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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
bignadad
Helper I
Helper I

Monthly Average of Running Total

I have a running total of assets by month and this is working fine.

 

bignadad_0-1708365314270.png

Here is my formula for the running total

RT Total = 
    VAR __Date = MAX(MasterDate[Dates])
    VAR __Table = FILTER(ALLSELECTED(MasterDate),MasterDate[Dates] <= __Date)
RETURN
    SUMX(__Table,[Total])

Total measure is

Total = CALCULATE(SUM(glentry[amount]))

The average should be 

22,393,778.19

 

Everything I have tried will not work.

What DAX formula will give me this result?

 

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how the semantic model looks like, but please try something like below whether it suits your requirement.

 

Running average =
VAR __Date =
    MAX ( MasterDate[Dates] )
VAR __Table =
    SUMMARIZE (
        FILTER ( ALLSELECTED ( MasterDate ), MasterDate[Dates] <= __Date ),
        MasterDate[YearMonth Sort Column]
    )
RETURN
    AVERAGEX ( __Table, [Total] )

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.


Go to My LinkedIn Page


I tried what you suggested

Average Invnetory = 
VAR __Date =
    MAX ( MasterDate[Dates] )
VAR __Table =
    SUMMARIZE (
        FILTER ( ALLSELECTED ( MasterDate ), MasterDate[Dates] <= __Date ),
        MasterDate[YearMonth]
    )
RETURN
    AVERAGEX ( __Table, [Total] )

 

But it returns 2.49 million

bignadad_0-1708366674358.png

Here is my master date table

bignadad_1-1708366708198.png

 

Could it be because of this blank year month value? 

bignadad_2-1708366989490.png

 

I found the issue with the blank value and removed it. this is what I have when I look at YearMonth with my CurrentInventory Total and CurrentInventory Running total

bignadad_3-1708367476338.png

This is my Dax based on your suggestion for running total

 

Average Invnetory = 
VAR __Date =
    MAX ( MasterDate[Dates] )
VAR __Table =
    SUMMARIZE (
        FILTER ( ALLSELECTED ( MasterDate ), MasterDate[Dates] <= __Date ),
        MasterDate[YearMonth]
    )
RETURN
    AVERAGEX ( __Table, [RT Current Inventory])

 

RT Current Inventory is

 

RT Current Inventory = 
    VAR __Date = MAX(MasterDate[Dates])
    VAR __Table = FILTER(ALLSELECTED(MasterDate),MasterDate[Dates] <= __Date)
RETURN
    SUMX(__Table,[Current Inventory])

 

This gives me 19326079.35 which is the average of all years.

So its the correct amount for all years but when I filter to 2023 i get this value

bignadad_4-1708367666683.png

What I would like it the average for the currently selected year. which should be 22,393,778.19 in 2023.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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