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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
chat_peters
Helper III
Helper III

Subtract a value from the same column

Hello, 

I am a little stuck here. I have a table below and I want to carry out the following subtract operation

1) Column A minus Column B for Index = 1

2) For every entry after that I want Column C minus Column B (Starting at index 2)

I am trying to reproduce Column C in power bi. Can someone please help?

chat_peters_0-1721244800506.png

 

3 ACCEPTED SOLUTIONS

@chat_peters Must not have had enough coffee yesterday. Here is the solution along with a PBIX file (attached below signature) where I include both a column and a measure solution.

 

Column C (Column) = 
  VAR __Index = [Index]
  VAR __Minus = SUMX( FILTER( 'Table', [Index] <= __Index ), [Column B] )
  VAR __Max = MAX( 'Table'[Column A] )
  VAR __Result = __Max - __Minus
RETURN
  __Result


Column C (Measure) = 
  VAR __Index = MAX([Index])
  VAR __Minus = SUMX( FILTER( ALLSELECTED('Table'), [Index] <= __Index ), [Column B] )
  VAR __Max = MAX( 'Table'[Column A] )
  VAR __Result = __Max - __Minus
RETURN
  __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi,

If you want a calculated column formula, then this works

Column = Data[Column A]-CALCULATE(SUM(Data[Column B]),FILTER(Data,Data[Index]<=EARLIER(Data[Index])))

Hope this helps.

Ashish_Mathur_0-1721434286431.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

If you want a measure, then refer to the attached file.

Ashish_Mathur_1-1721434637176.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

By any chance, do yuo have a Date column in your table?  If yes, then please share the table with the date column.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur I don't have a date table. There's really no data model. I just have this one table and I am trying to make this calculation work. I thought the index column should be good enough

If you want a measure, then refer to the attached file.

Ashish_Mathur_1-1721434637176.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

If you want a calculated column formula, then this works

Column = Data[Column A]-CALCULATE(SUM(Data[Column B]),FILTER(Data,Data[Index]<=EARLIER(Data[Index])))

Hope this helps.

Ashish_Mathur_0-1721434286431.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
chat_peters
Helper III
Helper III

@Greg_DecklerThank you for getting back.  I tried this one but I get an error for the last part stating that I used a wrong type of parameter into SUMX. I can't pass __Table variable into SUMX also by [__B] do you mean column B? or should I specify variable __B

VAR __Result = __Max - SUMX( __Table, [__B] )
chat_peters
Helper III
Helper III

@Greg_Deckler Thank you for answering. I got an error saying too many arguments were passed into SUMX. I wonder if I should create a virtual table with SUMMARIZE for the first value of column C and then keep subtracting. Any guidance would be greatly appreciated 🙂

@chat_peters Must not have had enough coffee yesterday. Here is the solution along with a PBIX file (attached below signature) where I include both a column and a measure solution.

 

Column C (Column) = 
  VAR __Index = [Index]
  VAR __Minus = SUMX( FILTER( 'Table', [Index] <= __Index ), [Column B] )
  VAR __Max = MAX( 'Table'[Column A] )
  VAR __Result = __Max - __Minus
RETURN
  __Result


Column C (Measure) = 
  VAR __Index = MAX([Index])
  VAR __Minus = SUMX( FILTER( ALLSELECTED('Table'), [Index] <= __Index ), [Column B] )
  VAR __Max = MAX( 'Table'[Column A] )
  VAR __Result = __Max - __Minus
RETURN
  __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@chat_peters My bad!

Column C (Column) =
  VAR __Index = [Index]
  VAR __Table = SUMX( FILTER( 'Table', [Index] <= __Index ), [Column B] )
  VAR __Max = MAX( 'Table'[Column A] )
  VAR __Result = __Max - SUMX( __Table, [__B] )
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@chat_peters Try this:

Column C (Column) =
  VAR __Index = [Index]
  VAR __Table = SUMX( FILTER( 'Table', [Index] <= __Index ), "__B", [Column B] )
  VAR __Max = MAX( 'Table'[Column A] )
  VAR __Result = __Max - SUMX( __Table, [__B] )
RETURN
  __Result
  


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.