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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors