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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
LB-Tech
Helper I
Helper I

I want Dax measure to solve this case!!!

LBTech_0-1731324524705.png

I have a input table like this 
i need a output column (i.e Output Amount ) I need a Dax measure to solve this scenerio
the table attached below is the explanation table to fetch my desired output.

LBTech_1-1731324596707.png

 

1 ACCEPTED SOLUTION

Hi @LB-Tech ,

 

Try to create the following measures:

Credit Total = SUM('Table'[Credit])

Debit Total = SUM('Table'[Debit])

Remaining Total = 
        VAR _totalCredit = CALCULATE(
			[Credit Total],
			ALL('Table'[Date])
		)
		VAR _Remaining = _totalCredit - CALCULATE(
			[Debit Total],
			'Table'[Date] <= MAX('Table'[Date])
		)
		RETURN
			IF(
				_Remaining > 0,
				_Remaining,
				0
			)

MFelix_0-1731407413651.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

6 REPLIES 6
LB-Tech
Helper I
Helper I

Hi @MFelix 
Thankyou for you DAX it worked well for Remaining Total Column, But my desired output is the last column (Output Amount Column) Could you guide me for the Output Column.

Hi @LB-Tech ,

 

Apologies for the incorrection change the measure Remaininig Total and add a new one:

 

Remaining Total = 
        VAR _totalCredit = CALCULATE(
			[Credit Total],
			ALL('Table'[Date])
		)
		VAR _Remaining = _totalCredit - CALCULATE(
			[Debit Total],
			'Table'[Date] <= MAX('Table'[Date])
        )
     Return
			
            _Remaining


Output Amount = 
        VAR _PreviousRemaining = SUMX(
			TOPN(
				1,
				FILTER(
					ALL('Table'[Date]),
					'Table'[Date] < MAX('Table'[Date])
				),
				'Table'[Date],
				DESC
			),
			[Remaining Total]
		)
		RETURN
			SWITCH(
				TRUE(),
				_PreviousRemaining = BLANK(), [Debit Total] - [Debit Total],
				_PreviousRemaining > [Debit Total], [Debit Total] - MIN(
					[Debit Total],
					_PreviousRemaining
				),
				_PreviousRemaining > 0, [Debit Total] - MAX(
					_PreviousRemaining,
					0
				),
				[Debit Total] - 0
			)

MFelix_0-1731501038567.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix 
The first Remaining Total Measure got right, but I am not getting the output amount measure 
But still figured out the required output by different measure.
Thankyou for your help.

MFelix
Super User
Super User

Hi @LB-Tech ,

 

There isn't enough information to get the values that you need, the first one I see is on the first row were you do a calculation 72.200 - 59.000. Where are the 72.200 coming from?

 

Also can you please share some mockup file and a litle bit more context in terms of semantic model?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



72200 is the total of the credit side. i have n no of party's, and they have debit and credit column. i need to take the total of the credit side of a party and set off against the debit column by date order. Then my output should be output column where i need the balance of debit amount date wise after setting off the credit total.

Hi @LB-Tech ,

 

Try to create the following measures:

Credit Total = SUM('Table'[Credit])

Debit Total = SUM('Table'[Debit])

Remaining Total = 
        VAR _totalCredit = CALCULATE(
			[Credit Total],
			ALL('Table'[Date])
		)
		VAR _Remaining = _totalCredit - CALCULATE(
			[Debit Total],
			'Table'[Date] <= MAX('Table'[Date])
		)
		RETURN
			IF(
				_Remaining > 0,
				_Remaining,
				0
			)

MFelix_0-1731407413651.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.