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
Anony_mous
Frequent Visitor

Calculating cumulative total of a column from a specified index

Hi All,

I am new to power bi I got a requirement like I need to start the logic from a specified index say for example I have 3 columns
Month, Positions, Rejected.Sample data is shown below:

MonthPositionsAccepted
22-Feb11 
22-Mar9 
22-Apr28

 

 

22-May40

 

 

22-Jun95
22-Jul17
22-Aug107
22-Sep312
22-Oct949
22-Nov3216
22-Dec2616
23-Jan4620
23-Feb2526
23-Mar3930
23-Apr726
23-May 23
23-Jun 35
23-Jul 26
23-Aug 22
23-Sep  
23-Oct  
23-Nov  
23-Dec  

So finally two columns will be added one for Positions column and the other for Rejected column.As we can see the first four rows of both strike and defeat column is blank that is because I have taken the indexing as 4 so it will skip the first 4 rows and start from 5th row similarly if the indexing is 3 it will skip first 3 rows and start indexing from 4th row. Columns Positions,Strike are related it means the 1st row value of positions column is appearing in 5th row of Strike column since we have given the constant indexing as 4.likewise the sum of 1st and 2nd row value of positions column will be the value for 6th row of Strike column (cumulative total).Columns Rejected,Defeat are related it means the 1st row value of Rejected column is appearing in 5th row of Defeat column since we have given the constant indexing as 4.likewise the sum of 1st and 2nd row value of Rejected column will be the value for 6th row of Defeat column (cumulative total).Finally the data will have 2 new columns Strike and Defeat.The data is shown below:

Please give some solutions.All suggestions are welcome thank you in advance!!

Regards,

Anony_mous

StrikeDefeat
  
  
  
  
115
2012
4819
8831
9740
9856
10872
11192
205118
237148
263174
309197
334232
373258
380280
380280
380280
380280
380280
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anony_mous 

 

First add an Index column to your table with Power Query Editor. 

vjingzhang_0-1685000819942.png

Then create the following new columns with DAX. I provide the indexing number as a variable in the formula. 

Strike = 
var indexing = 4
return
CALCULATE(SUM('Table'[Positions]),ALL('Table'),'Table'[Index]>=1,'Table'[Index]<=EARLIER('Table'[Index])-indexing)
Defeat = 
var indexing = 4
return
CALCULATE(SUM('Table'[Accepted]),ALL('Table'),'Table'[Index]>=indexing+1,'Table'[Index]<=EARLIER('Table'[Index]))

vjingzhang_1-1685001465490.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @Anony_mous 

 

First add an Index column to your table with Power Query Editor. 

vjingzhang_0-1685000819942.png

Then create the following new columns with DAX. I provide the indexing number as a variable in the formula. 

Strike = 
var indexing = 4
return
CALCULATE(SUM('Table'[Positions]),ALL('Table'),'Table'[Index]>=1,'Table'[Index]<=EARLIER('Table'[Index])-indexing)
Defeat = 
var indexing = 4
return
CALCULATE(SUM('Table'[Accepted]),ALL('Table'),'Table'[Index]>=indexing+1,'Table'[Index]<=EARLIER('Table'[Index]))

vjingzhang_1-1685001465490.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

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.