cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Milan14
Frequent Visitor

How to calculate the amount retained based on conditions

Hello everyone,

 

I would like to calculate the amount retained from date slicer, selected 1/7/2021 until 3/7/2021, only include those USERID who performed top-up in the same period. Also, I would like to show the amount retained = 0 for those users who performed payment more than the top-up amount.

 

Below shows the formula I used to calculate the amount retained:

Amount retained = Top-up amount – payment amount

 

Sample table:

Milan14_0-1630471145722.png

Expected outcome in table:

Milan14_1-1630471181101.png

Expected outcome in card:

Amount Retained

70

 

Thanks.

 

3 REPLIES 3
VahidDM
Community Champion
Community Champion

Hi @Milan14 

Try these 3 measures:

Amount Retained =
VAR _TP =
    CALCULATE ( MAX ( 'Table'[Amount] ), 'Table'[Transaction Type] = "TopUp" )
VAR _PY =
    CALCULATE ( MAX ( 'Table'[Amount] ), 'Table'[Transaction Type] = "Payment" )
VAR _Dif = _TP - _PY
RETURN
    IF ( _Dif < 0, 0, _Dif )

 

Payment Amount =
VAR _TP =
    CALCULATE ( MAX ( 'Table'[Amount] ), 'Table'[Transaction Type] = "TopUp" )
VAR _PY =
    CALCULATE ( MAX ( 'Table'[Amount] ), 'Table'[Transaction Type] = "Payment" )
RETURN
    IF ( _TP = 0, 0, _PY )

 

Top-Up Amount =
CALCULATE ( MAX ( 'Table'[Amount] ), 'Table'[Transaction Type] = "TopUp" )

 

Output:

VahidDM_1-1630654984328.png

 

 

 

 

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

Appreciate your Kudos VahidDM_0-1630654938946.png!!

amitchandak
Super User
Super User

@Milan14 , Create a measure like

 

measure =
var _1 = calculate(sum(Table[Amount]), filter(Table, Table[Transaction_type] ="TopUp"))
var _2 = calculate(sum(Table[Amount]), filter(Table, Table[Transaction_type] ="Payment"))
return
sumx(Values(Table[UserID]), if(_1>_2, _1 -_2, blank()))

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Hi @amitchandak 

 

Thanks for your suggestion. I have tried out with the formula you provided, but It doesn't work out.

 

This is the outcome I get with the formula you provided:

Milan14_0-1630650146333.png

 

This is my expected outcome in table:

Milan14_1-1630650253647.png

 

Have any idea what kind of formula I can apply to solve this issue?

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors