cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

## Progressively sum values for periods of time

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])

1 ACCEPTED SOLUTION
Super User

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.

2 REPLIES 2
Super User

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.

Anonymous
Not applicable

hi travbum,

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.