Forum Discussion
dax for calculating sum PTD based on different columns
- 5 years ago
It cannot be a calculated column. Those never recalculate during use and ignore user selection.
A measure of = SUM(Table[Sales]) will work. If you put the site, Month, and Week in a visual and filter based on those, it will automatically calculate your values. Nothing fancy needed at all.
If you are trying to get a cumulative total, the correct way is to use a date table, but you can do it with your data.
PTD = VAR varCurrentSite = MAX('Table'[Site]) VAR varCurrentMonth = MAX('Table'[Month]) VAR varCurrentWeek = MAX('Table'[Week]) RETURN CALCULATE( SUM('Table'[Sales]), FILTER( ALL('Table'), 'Table'[Site] = varCurrentSite && 'Table'[Month] = varCurrentMonth && 'Table'[Week] <= varCurrentWeek ) ) - 5 years ago
Hi, Anonymous , you might want to try such a calculated column
PTD = SUMX ( FILTER ( Table1, Table1[Site] = EARLIER ( Table1[Site] ) && Table1[Month] = EARLIER ( Table1[Month] ) && Table1[Week] <= EARLIER ( Table1[Week] ) ), Table1[Sales] )
It cannot be a calculated column. Those never recalculate during use and ignore user selection.
A measure of = SUM(Table[Sales]) will work. If you put the site, Month, and Week in a visual and filter based on those, it will automatically calculate your values. Nothing fancy needed at all.
If you are trying to get a cumulative total, the correct way is to use a date table, but you can do it with your data.
PTD =
VAR varCurrentSite = MAX('Table'[Site])
VAR varCurrentMonth = MAX('Table'[Month])
VAR varCurrentWeek = MAX('Table'[Week])
RETURN
CALCULATE(
SUM('Table'[Sales]),
FILTER(
ALL('Table'),
'Table'[Site] = varCurrentSite
&& 'Table'[Month] = varCurrentMonth
&& 'Table'[Week] <= varCurrentWeek
)
)