Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
travbum
Advocate I
Advocate I

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
technolog
Super User
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.

View solution in original post

2 REPLIES 2
technolog
Super User
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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors