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
Analitika
Post Prodigy
Post Prodigy

How count subtract of numbers in Power BI?

Hello, I have some data. I need to calculate a  subtraction.

Analitika_0-1634116816565.png

 

I have a table and I need to calculate a difference (CRE-DET) (in this case it will be 8000-6000) not (8000-0 or 0-6000). How to write DAX formula?

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @Analitika 

 

I have seen your another case, they seem to be the same problem.

You can try the following formula to create a new column.

 

Difference =
VAR _maxCRE =
    MAXX( FILTER( 'Table', [ID] = EARLIER( 'Table'[ID] ) ), [CRE] )
VAR _maxDET =
    MAXX( FILTER( 'Table', [ID] = EARLIER( 'Table'[ID] ) ), [DET] )
RETURN
    IF( [DET] = _maxDET, _maxCRE - _maxDET, BLANK() )

 

vchenwuzmsft_0-1634523900600.png

 

I have the following questions, can you explain them?.

    1 you need column or measure?

    2 the condition choose 8000 and 6000 to calculate, is it they are the max of current capacity?

    3 only display the result in one row or all the rows?

 

I put my pbix file in the attachment you can reference.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-chenwuz-msft
Community Support
Community Support

Hi @Analitika 

 

I have seen your another case, they seem to be the same problem.

You can try the following formula to create a new column.

 

Difference =
VAR _maxCRE =
    MAXX( FILTER( 'Table', [ID] = EARLIER( 'Table'[ID] ) ), [CRE] )
VAR _maxDET =
    MAXX( FILTER( 'Table', [ID] = EARLIER( 'Table'[ID] ) ), [DET] )
RETURN
    IF( [DET] = _maxDET, _maxCRE - _maxDET, BLANK() )

 

vchenwuzmsft_0-1634523900600.png

 

I have the following questions, can you explain them?.

    1 you need column or measure?

    2 the condition choose 8000 and 6000 to calculate, is it they are the max of current capacity?

    3 only display the result in one row or all the rows?

 

I put my pbix file in the attachment you can reference.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Tahreem24
Super User
Super User

@Analitika , Check the beloe DAX and screen shot also.

New Measure =
VAR a = CALCULATE(SUM(MyTable[DRE]),FILTER(ALL(MyTable),MyTable[Date]<MAX(MyTable[Date])))+0
RETURN SUM(MyTable[CRE])-a
 
Capture.JPG
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

That solution not works for me well. I am getting wrong answers. 

Analitika_0-1634129641977.png

 

It's wrong. I am getting 

Analitika_0-1634123688492.png

Also my table has more objects with dre and cre each ID.

amitchandak
Super User
Super User

@Analitika , Try measure like

 

Sum(Table[CRE]) -Sum(Table[DET])

 

or

 

calculate(Sum(Table[CRE]) -Sum(Table[DET]), allexcept(Table, Table[ID]) )

 

or

 

calculate(Sum(Table[CRE]) -Sum(Table[DET]), filter(allselected(Table), Table[ID] = max(Table[ID])) )

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

It's wrong. Subtract is getting like this 

Analitika_0-1634118997228.png

 

Result should be 8000-6000=2000

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.

Top Kudoed Authors