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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
imadtn
Frequent Visitor

Calculating loan paid and loan draw down

Dear all, new to DAX and appreciate some help..

I am trying to calculate loan repayment YTD and loan draw down YTD as measures. But all I have in my data is loan balances by loan from general ledger and by date.

 

Making a simple measure as "Term loans Today"- "Term loans end of last year" gives the net difference, so it doesnt work as i need amount paid and amount drawn for each loan.

 

So,  I am ok with taking the difference for each loan alone, if it is an increase its a drawdown and if it is a decrease it is a repayment. Then i need to sum up draw downs and repayments of each loan to get the total. The problem is how to do the logic for summing the differences?


See the table below and following is the formulas for the measures. For each loan [Paid amount] and [Drawdown amount] is showing correctly but the totals are not correct as the logic needs to be different than what it is inside the table. Any ideas?

Paid amount = if([Term loans today]>=[Term loans end of last year],BLANK(),ABS([Term loans end of last year]-[Term loans today]))
Drawdown amount = if([Term loans today]<[Term loans end of last year],BLANK(),ABS([Term loans end of last year]-[Term loans today]))

 

 loans capture.PNG

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @imadtn

 

You should be able to fix this using SUMX.

SUMX can iterate over the loans, computing Paid amount & Drawdown amount for each loan, and then summing.

 

It looks like Loan code or something similar is the Loan dimension.

Give these measures a go, replacing YourTable[Loan code] with the appropriate column reference:

Paid amount =
SUMX (
    VALUES ( YourTable[Loan code] ),
    VAR LoansToday = [Term loans today]
    VAR LoansLastYear = [Term loans end of last year]
    RETURN
        IF ( LoansToday < LoansLastYear, ABS ( LoansLastYear - LoansToday ) )
)
Drawdown amount =
SUMX (
    VALUES ( YourTable[Loan code] ),
    VAR LoansToday = [Term loans today]
    VAR LoansLastYear = [Term loans end of last year]
    RETURN
        IF ( LoansToday >= LoansLastYear, ABS ( LoansLastYear - LoansToday ) )
)

Note:

  • I used variables to avoid repeated evaluation of measures.
  • I inverted the comparisons within each IF, so that result_if_true is nonblank (it just makes the code a little shorter as result_if_false defaults to BLANK() )

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @imadtn

 

You should be able to fix this using SUMX.

SUMX can iterate over the loans, computing Paid amount & Drawdown amount for each loan, and then summing.

 

It looks like Loan code or something similar is the Loan dimension.

Give these measures a go, replacing YourTable[Loan code] with the appropriate column reference:

Paid amount =
SUMX (
    VALUES ( YourTable[Loan code] ),
    VAR LoansToday = [Term loans today]
    VAR LoansLastYear = [Term loans end of last year]
    RETURN
        IF ( LoansToday < LoansLastYear, ABS ( LoansLastYear - LoansToday ) )
)
Drawdown amount =
SUMX (
    VALUES ( YourTable[Loan code] ),
    VAR LoansToday = [Term loans today]
    VAR LoansLastYear = [Term loans end of last year]
    RETURN
        IF ( LoansToday >= LoansLastYear, ABS ( LoansLastYear - LoansToday ) )
)

Note:

  • I used variables to avoid repeated evaluation of measures.
  • I inverted the comparisons within each IF, so that result_if_true is nonblank (it just makes the code a little shorter as result_if_false defaults to BLANK() )

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hi Owen, 
Thanks for the reply. I had solved the issue by deriving a new table from my data set and making the paid and drawdown amount as a calculated column. 

Your solution is much better though, I tested and it works, and thanks for the tips.
Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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