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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Analitika
Post Prodigy
Post Prodigy

How count difference between two numbers per different row in Power BI?

  Analitika_0-1634138234846.png

Hello,

 

I have a data in table. I need to count difference between CRE and DET. I need to count CRE-DET (8000-6000=2000). How to do it in DAX formula? I am expecting the result like this:

Analitika_2-1634138523574.png

I have tried these: 

New column =

var _max = maxx(filter(Table, [C4] <[C4]),[C4])

var _val = sumx(filter(Table,[C4] =_max), [C2]+[C3])

return

[C2+[C3] - _val

 

   Column = VAR _0 = MAXX(FILTER('Fact','Fact'[Column4]<EARLIER('Fact'[Column4])),'Fact'[Column3]) VAR _3 = _0-CALCULATE(MAX('Fact'[Column2])) RETURN _3 

 

Measure=var Credit=SUM('your_table'[CRE])

var Debit=SUM('you_table'[DET])

return Credit-Debit

 

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])) )

 

VAR a = CALCULATE(SUM(MyTable[DRE]),FILTER(ALL(MyTable),MyTable[Date]<MAX(MyTable[Date])))+0

RETURN SUM(MyTable[CRE])-a

 

 

None of these helped me.

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

Hi @Analitika 

 

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-1634523601435.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

1 REPLY 1
v-chenwuz-msft
Community Support
Community Support

Hi @Analitika 

 

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-1634523601435.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.

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.