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
murillocosta
Helper I
Helper I

Previous Row Value from the same column

Hi. Would someone able to help me with the below?

 

I need to calculate a new column named "Total Outbound FINAL". This columns will need to sum the last 7 "Total Outbound" column rows values

 

- For example if I want to calculate 2023-W10 like below I will need to perform the calculation

 

86 + 317 + 353 + 301 + 339 + 254 + 308 = 1958

murillocosta_2-1677540944321.png

 

murillocosta_3-1677541049071.png

 

murillocosta_4-1677541062856.png

 

Calculating the first rows is fine as you can see in the screen above.

murillocosta_2-1677540944321.png

My question is how to calculate the next row and also include 2023-W10 as one of the 7 previous row??? So my 2023-W11 should be:

1958 + 86 + 317 + 353 + 301 + 339 + 254 = 3608

 

The expected result should be like this

murillocosta_5-1677541459590.png

Thanks

 

 

 

 

1 REPLY 1
MAwwad
Super User
Super User

 

To calculate the rolling sum of the last 7 rows of the "Total Outbound" column, you can use the DAX function called SUMX. Here is the formula you can use:

 

 
Total Outbound FINAL = SUMX( FILTER( 'your_table_name', 'your_table_name'[YearWeek] <= MAX('your_table_name'[YearWeek]) && 'your_table_name'[YearWeek] > MAXX('your_table_name', 'your_table_name'[YearWeek]) - 7 ), 'your_table_name'[Total Outbound] )
 

In this formula, replace 'your_table_name' with the actual name of your table, and 'YearWeek' and 'Total Outbound' with the names of your columns.

This formula uses the MAX function to get the maximum value of the "YearWeek" column, and then uses MAXX to get the maximum value of the "YearWeek" column in the previous row. It then filters the table to include only the rows with a "YearWeek" value less than or equal to the maximum "YearWeek" value, and greater than the maximum "YearWeek" value minus 7 (to get the last 7 rows). Finally, it sums the "Total Outbound" column for these filtered rows.

Note that this formula assumes that your "YearWeek" column is formatted as text in the format "YYYY-W##". If it's formatted differently, you may need to adjust the formula accordingly.

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