cancel
Showing results for
Did you mean:

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.

____________
Please join the Power BI User Group if you need help with dashboard design and usability
https://community.powerbi.com/t5/Power-BI-UX-UI-User-Group/gh-p/PowerBIUXUIUserGroup

Subscribe to my medium blog
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.

____________
Please join the Power BI User Group if you need help with dashboard design and usability
https://community.powerbi.com/t5/Power-BI-UX-UI-User-Group/gh-p/PowerBIUXUIUserGroup

Subscribe to my medium blog
Anonymous
Not applicable

hi travbum,

Announcements

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Exclusive opportunity for Women!

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!

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors