Forum Discussion

ElliotP's avatar
ElliotP
Post Prodigy
10 years ago
Solved

Sum past week with dateadd function

Morning,

 

I could have sworn I have used this before and for some reason now it isn't working.

 

I'm attempting to calculate the sum of sessions of the past seven days on a rolling basis. I have a date table, with a relationship to the date of the table containing the number of sessions per day and date.

 

Formula used;

SumpastweekSessions = CALCULATE(Sum('NumberofSessions'[Sessions]), DATEADD('NumberofSessionsDateTable'[DateKey], -7,DAY))

The answer should be 30; but instead I'm recieving 2734.

 

When I change the number of the interval the value changes; I feel I'm missing something here.

 

 

  • I solved it lads, no clue what I'm feeling on this one. I'd love an explanation but I feel I just misinterpreted what DATEADD does a long time ago and I just haven't noticed I've been calculating the wrong values.

     

    Code I ended up using;

    SumpastweekSessions = CALCULATE(Sum('NumberofSessions'[Sessions]), DATESINPERIOD('NumberofSessionsDateTable'[DateKey],TODAY(),-7,DAy)) 

    I tried datesbetween as well.

1 Reply

  • I solved it lads, no clue what I'm feeling on this one. I'd love an explanation but I feel I just misinterpreted what DATEADD does a long time ago and I just haven't noticed I've been calculating the wrong values.

     

    Code I ended up using;

    SumpastweekSessions = CALCULATE(Sum('NumberofSessions'[Sessions]), DATESINPERIOD('NumberofSessionsDateTable'[DateKey],TODAY(),-7,DAy)) 

    I tried datesbetween as well.