DAX measure running total by month

dicken

Active Member
Joined
Feb 12, 2022
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I know there's a lot of stuff out there about CALCULATE, but I wonder if someone can point me in the right direction,
I've created a running total by each month using DAX as a calculated column. I've also got the same as a measure , the difference is the definition of the variable , in
the measure it seems to need to be max(date ) ;

< Newm2:=VAR Sdate = Table1[Date]

RETURN CALCULATE(SUM([Unit]),Table1[Date]<= Sdate && Table1[Date]> EOMONTH(Sdate,-1)) >

But for the measure I use

Newm2:=VAR maxdate = MAX(Table1[Date])

RETURN CALCULATE(SUM([Unit]),Table1[Date]<= maxdate && Table1[Date]> EOMONTH(maxdate,-1))

I've been trying to understand / visualize (as it is dropped into a pivot table ) how the Calculate affects the variable or if it does at all ? #

Richard
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
In a calculated column you have row context, since each row has a date in it, so you just want to sum values less than or equal to the date in that row.

In a measure there is no row context, since you are aggregating multiple rows. That means you need to calculate the latest date that matches your current filter context (i.e. the maximum date of all the rows being aggregated for the specific cell the measure is in), then calculate the sum of all the Units up to that date.

Does that make sense?
 
Upvote 0
Solution
In a calculated column you have row context, since each row has a date in it, so you just want to sum values less than or equal to the date in that row.

In a measure there is no row context, since you are aggregating multiple rows. That means you need to calculate the latest date that matches your current filter context (i.e. the maximum date of all the rows being aggregated for the specific cell the measure is in), then calculate the sum of all the Units up to that date.

Does that make sense?
Hi Rory,
thanks, yes it does make sense, my own thinking was along the right lines, but you've put it very clearly.

RD
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,629
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top