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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Calculate sum of current values according to current date over categories

I have a table of loan data for ships, where each ship has an associated loan and loan currency. The loans are paid back by instalments at fixed payment dates. For each ship and for each currency, I want to calculate the total remaining EUR and USD loans at each payment date, either as a measure or column, as shown in the 2 columns on the right.

 

ShipCurrencyRemaining loanPayment date[Total EUR loan][Total USD loan]
AEUR10 000 00013.02.202210 000 0004 500 000
AEUR9 000 000

13.05.2022

10 500 000

4 500 000

AEUR8 000 00013.08.20229 400 00011 900 000
BEUR1 500 00027.04.2022  
BEUR1 400 00027.07.2022  
BEUR1 300 00027.10.2022  
CUSD5 000 00015.01.2021  
CUSD4 500 00015.01.2022  
CUSD4 000 00015.01.2023  
DUSD7 400 00022.07.2022  
DUSD7 200 00022.10.2022  
DUSD7 000 00022.01.2023  

 

As you can see, there are both previous and future dates. I have tried using combinations of SUMX, SUMMARIZE, FILTER, MAX, VALUES, LOOKUPVALUE, etc. The idea is to graph the total EUR and USD loan value to see what potential investment opportunities lies ahead. I hope someone is able to help me with this one.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

For anyone concerned, I got a working solution from one of our Power BI consultants.

 

This measure will return the sum of the remaining facility for each loan at any given date (I realize my phrasing was a bit inacurrate in the first post, asking for the remaining facility at each payment date).

 

Current Remaining Facility Measure = 

VAR selecteddate = MAX ( 'Date Table'[Date] )
VAR facility_vessel =
    CALCULATETABLE (
        SUMMARIZE (
            'Loan Data',
            'Loan Data'[Vessel],
            "remaining_facility",
                VAR lastdata =
                    CALCULATE (
                        MAX ( 'Loan Data'[Payment date] ),
                        'Loan Data'[Payment date] <= selecteddate
                    )
                VAR remaining =
                    CALCULATE (
                        MAX ( 'Loan Data'[Remaining facility] ),
                        'Loan Data'[Payment date] = lastdata
                    )
                RETURN
                    remaining
        ),
        REMOVEFILTERS ( 'Date Table' )
    )
VAR result = SUMX ( facility_vessel, [remaining_facility] )
RETURN
    result

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

For anyone concerned, I got a working solution from one of our Power BI consultants.

 

This measure will return the sum of the remaining facility for each loan at any given date (I realize my phrasing was a bit inacurrate in the first post, asking for the remaining facility at each payment date).

 

Current Remaining Facility Measure = 

VAR selecteddate = MAX ( 'Date Table'[Date] )
VAR facility_vessel =
    CALCULATETABLE (
        SUMMARIZE (
            'Loan Data',
            'Loan Data'[Vessel],
            "remaining_facility",
                VAR lastdata =
                    CALCULATE (
                        MAX ( 'Loan Data'[Payment date] ),
                        'Loan Data'[Payment date] <= selecteddate
                    )
                VAR remaining =
                    CALCULATE (
                        MAX ( 'Loan Data'[Remaining facility] ),
                        'Loan Data'[Payment date] = lastdata
                    )
                RETURN
                    remaining
        ),
        REMOVEFILTERS ( 'Date Table' )
    )
VAR result = SUMX ( facility_vessel, [remaining_facility] )
RETURN
    result
lbendlin
Super User
Super User

Are you concerned about exchange rates?  If so, are they part of your data model?

 

Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Anonymous
Not applicable

Thank you for your reply.

 

You can find the sample data here: https://we.tl/t-KOHYUbsMTz

 

What I want is to sum the Remaining Facility at any time. I am not concerned about currency exchange rates.

 

This is the result I am looking for:

Picture.jpg

I don't know if you actually need to calculate anything explicitly. Would something like this work?

 

lbendlin_0-1664309674993.png

 

Anonymous
Not applicable

I actually need them all summed up in one graph. I have tried to not calculate anything, but that results in this graph, which is not quite what I want:

 

Screenshot 2022-09-29 112312.png

 

So for now, I have put together one calculated column for EUR loans and one for USD loans for each date in the Date Table. They look like this:

 

EUR Loans = 

var VesselB = CALCULATE(LOOKUPVALUE('Loan Data'[Remaining facility],'Loan Data'[Payment date],LASTDATE('Loan Data'[Payment date]),'Loan Data'[Vessel],"Vessel B"),FILTER('Loan Data','Loan Data'[Payment date]<='Date'[Date]&&'Loan Data'[Vessel]="Vessel B"))

var VesselC = CALCULATE(LOOKUPVALUE('Loan Data'[Remaining facility],'Loan Data'[Payment date],LASTDATE('Loan Data'[Payment date]),'Loan Data'[Vessel],"Vessel C"),FILTER('Loan Data','Loan Data'[Payment date]<='Date'[Date]&&'Loan Data'[Vessel]="Vessel C"))

var VesselD = CALCULATE(LOOKUPVALUE('Loan Data'[Remaining facility],'Loan Data'[Payment date],LASTDATE('Loan Data'[Payment date]),'Loan Data'[Vessel],"Vessel D"),FILTER('Loan Data','Loan Data'[Payment date]<='Date'[Date]&&'Loan Data'[Vessel]="Vessel D"))

var VesselE = CALCULATE(LOOKUPVALUE('Loan Data'[Remaining facility],'Loan Data'[Payment date],LASTDATE('Loan Data'[Payment date]),'Loan Data'[Vessel],"Vessel E"),FILTER('Loan Data','Loan Data'[Payment date]<='Date'[Date]&&'Loan Data'[Vessel]="Vessel E"))

return VesselB+VesselC+VesselD+VesselE

USD Loans = 

var VesselA = CALCULATE(LOOKUPVALUE('Loan Data'[Remaining facility],'Loan Data'[Payment date],LASTDATE('Loan Data'[Payment date]),'Loan Data'[Vessel],"Vessel A"),FILTER('Loan Data','Loan Data'[Payment date]<='Date'[Date]&&'Loan Data'[Vessel]="Vessel A"))

var VesselF = CALCULATE(LOOKUPVALUE('Loan Data'[Remaining facility],'Loan Data'[Payment date],LASTDATE('Loan Data'[Payment date]),'Loan Data'[Vessel],"Vessel F"),FILTER('Loan Data','Loan Data'[Payment date]<='Date'[Date]&&'Loan Data'[Vessel]="Vessel F"))

return VesselA+VesselF

This results in this graph, which is more in line with what I want:

Screenshot 2022-09-29 112820.png

 

Do you see any way I can write this in a more compact manner?

 

 

Measure = 
var md = max('Loan Data'[Payment date])
var a = ADDCOLUMNS(allselected('Loan Data'[Vessel]),"md",CALCULATE(max('Loan Data'[Payment date]),'Loan Data'[Payment date]<=md))
var b = ADDCOLUMNS(a,"mv",var v=[Vessel] var m=[md] return CALCULATE(max('Loan Data'[Remaining facility]),'Loan Data'[Vessel]=v,'Loan Data'[Payment date]=m))
return sumx(b,[mv])

 

lbendlin_1-1664457441086.png

 

 

 

Anonymous
Not applicable

Thank you, that's very good and it works really well looking at each year:

 

Screenshot 2022-09-30 100937.png

 

However, looking at each quarter I get some of the same issue, as not every loan has data points for each quarter (bi-annual payments). That's why I tried putting the calculations in the Date table for each date. Do you see any way to implement that in your measure? I have tried to look at it myself, but without luck unfortunately.

alesvo_0-1664525558836.png

To report on things that are not there you need to use disconnected tables and/or crossjoins.

Anonymous
Not applicable

I will try, thank you.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors