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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Tony_Singh
New Member

DAX code assistance please:

Hi there please would someone be able to assist with a 14 day rolling average query for a column calculation in PBI,

Dates are dd/mm/yy and I have Currency data in the Budget column I am looking to write a formula for the 14 day rolling total from which to calculate the rolling average.

The following formula only returns a rolling 1 day average:

Rolling Budget = CALCULATE(sum(INFEED[BUDGET]),DATESINPERIOD('INFEED'[DATE].[Date],LASTDATE('INFEED'[DATE].[Date]),14,DAY))
Tony_Singh_0-1666176409535.png

With thanks & kind regards, Singh,

1 ACCEPTED SOLUTION

@Tony_Singh 

My mistake. Somehow I missed to remove the filters. 

Rolling Budget =
VAR CurrentDate = 'INFEED'[DATE]
VAR PreviousDate = CurrentDate - 14
RETURN
    CALCULATE (
        SUM ( INFEED[BUDGET] ),
        'INFEED'[DATE] <= CurrentDate,
        'INFEED'[DATE] >= PreviousDate,
        REMOVEFILTERS ()
    )

View solution in original post

6 REPLIES 6
tamerj1
Community Champion
Community Champion

Hi @Tony_Singh 

please try

Rolling Budget =
VAR CurrentDate = 'INFEED'[DATE]
VAR PreviousDate = CurrentDate - 14
RETURN
    CALCULATE (
        SUM ( INFEED[BUDGET] ),
        'INFEED'[DATE] <= CurrentDate,
        'INFEED'[DATE] >= PreviousDate
    )

Tony_Singh_0-1666190617987.png

Hi there, it is only returning the single value ie the pickup value,

In essence we need to aggregate the first 14 days ie 1-14, then 2-15, then 3-16 and so on a bit of a dilema,

Any further suggestions?

Regards,

@Tony_Singh 

My mistake. Somehow I missed to remove the filters. 

Rolling Budget =
VAR CurrentDate = 'INFEED'[DATE]
VAR PreviousDate = CurrentDate - 14
RETURN
    CALCULATE (
        SUM ( INFEED[BUDGET] ),
        'INFEED'[DATE] <= CurrentDate,
        'INFEED'[DATE] >= PreviousDate,
        REMOVEFILTERS ()
    )
Greg_Deckler
Community Champion
Community Champion

@Tony_Singh Try:

Rolling Average Measure =
  VAR __MaxDate = MAX('DATE'[Date])
  VAR __MinDate = __MaxDate - 14
RETURN
  SUMX(FILTER('INFEED',[Date] >= __MinDate && [Date] <= __MaxDate),[BUDGET])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, as I am newbie please do not take any offence this works as a caluclated measure however how would i write that as a column command, kind regards & thanks, Singh,

Hi Greg, I have looked in the book also, I have the first edition, still struggling with the technicality, I have copied and pasted the code from your reply into the formula bar and I get a value of 1875 which is 15*125, the 125 is the last daily value for the daily budget ie 31/12/2024, 

Tony_Singh_0-1666180673187.png

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.