I've got a table with:
Date -- Amount -- Weeks Ago
10/24 -- 5 -- 0
10/23 -- 2 -- 0
10/22 -- 1 -- 1
...
10/14 -- 3 -- 2
Where Date has one entry per day, Amount, is a random value from 0 to 5, and Weeks Ago is the difference between Today() and the Date in weeks of the year. I want to output a graph that has the last 7 weeks while progressively adding the amounts together. Using the data above,
Week 0 = (5 + 2 + 1 + ... + 2)
Week 1 = (1 + ... + 2)
Week 2 = 2
Here is my first attempt at doing this. Am I anywhere close? Do I even have the right approach?
Sum Each Weeks Ago = SUMX( CALCULATETABLE('Sheet1'[Amount],
'Sheet1'[Weeks Ago] = 0,
'Sheet1'[Weeks Ago] = 1),
'Sheet1'[Weeks Ago] = 2),
'Sheet1'[Amount])
Solved! Go to Solution.
Your objective is to create a running total of the "Amount" column, but segregated by the "Weeks Ago" value. The idea you're going for is correct, but the expression seems to have some misunderstandings in DAX syntax and how to apply filter contexts.
You'll want to sum the amounts for all the rows where "Weeks Ago" is equal to or less than the current "Weeks Ago". Here's one way to express this in DAX:
Sum Until Weeks Ago =
VAR CurrentWeek = MAX('Sheet1'[Weeks Ago])
RETURN
SUMX(
FILTER(
'Sheet1',
'Sheet1'[Weeks Ago] <= CurrentWeek
),
'Sheet1'[Amount]
)
How this works:
VAR CurrentWeek captures the "Weeks Ago" value of the current row/context.
The FILTER function is used to create a table that only includes rows from Sheet1 where "Weeks Ago" is less than or equal to the current "Weeks Ago".
SUMX then sums the "Amount" values for all the rows in this filtered table.
When you plot "Weeks Ago" against this measure, you should get the running total you're looking for.
Your objective is to create a running total of the "Amount" column, but segregated by the "Weeks Ago" value. The idea you're going for is correct, but the expression seems to have some misunderstandings in DAX syntax and how to apply filter contexts.
You'll want to sum the amounts for all the rows where "Weeks Ago" is equal to or less than the current "Weeks Ago". Here's one way to express this in DAX:
Sum Until Weeks Ago =
VAR CurrentWeek = MAX('Sheet1'[Weeks Ago])
RETURN
SUMX(
FILTER(
'Sheet1',
'Sheet1'[Weeks Ago] <= CurrentWeek
),
'Sheet1'[Amount]
)
How this works:
VAR CurrentWeek captures the "Weeks Ago" value of the current row/context.
The FILTER function is used to create a table that only includes rows from Sheet1 where "Weeks Ago" is less than or equal to the current "Weeks Ago".
SUMX then sums the "Amount" values for all the rows in this filtered table.
When you plot "Weeks Ago" against this measure, you should get the running total you're looking for.
hi travbum,
for inspiration, see: http://www.powerpivotpro.com/2011/06/running-totals-without-a-traditional-calendar-table/
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!