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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
AnaCh_
Frequent Visitor

How can I create a calculated column that calculates the running total of the last 13 periods?

This table contains several rich identifiers that should be took in consideration when calculating the running total.

 

Should I create a calculated column or a measure?

 

The thing is that when creating the measure, and adding it to a matrix, slicers dont work if I want to only see information for a specific country.  If I apply a filter by country the measure shows the values for all rows with the country selected, and the other countries show the sum of the entire table, and still appear in the table instead of dissapearing. 

 

I have a week column identifier, and I added an index column to enumerate each column them.

 

This is the code I was using for the measure, so the current week and the previous weeks can have their own running total taking in consideration the previous 13 weeks.

 

Sum of 13 Previous Weeks Total Units =

CALCULATE([Sum of Total Units],

      FILTER(ALL('Table1'), 'Table1'[Index]=SELECTEDVALUE('Table1'[Index]) ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+1 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+2 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+3 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+4 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+5 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+6 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+7 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+8 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+9 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+10 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+11 ||

'Table1'[Index]=SELECTEDVALUE('Table1'[Index])+12 &&

'Table1'[Country]= SELECTEDVALUE('Table1'[Country]) && ..... (repeats for each rich identifer)

))

 

Thank you in advance for the guidance 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@AnaCh_ , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

with help from week Index or Rank you can can rolling measure easily

 

example

rank or index(if only week wise data. Use a seperate week or date Table

Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
measures

Last 13 weeks = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-13 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@AnaCh_ , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

with help from week Index or Rank you can can rolling measure easily

 

example

rank or index(if only week wise data. Use a seperate week or date Table

Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
measures

Last 13 weeks = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-13 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Amitchandak,

 

Could you please help me now with this one?

 

Your help is really appreciated!

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/How-to-calculate-the-max-of-a-measure-in-a-ma...

Thank you very much this was pretty useful!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors