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
hgrangeret
Frequent Visitor

Calculate opening and closing balances across multiple periods

Hi,

 

Here is my dataset:

AccountPERIOD YEARPERIOD NAMEBeginning BalanceClosing Balance
100402019Apr-19960019775211
100402019Aug-19219255219255
100402019Jul-19214425219255
100402019Jun-19785203214425
100402019May-19775211785203
100402019Oct-19219255219255
100402019Sep-19219255219255

 

I have opening and closing balances for different Gl accounts  for a given fiscal year, for different periods.

My users want to filter on a set of periods (in the same FY), eg from Apr-19 to May-19 and show the opening and closing balances  for each account of the selected range of periods.

It should look like this:

AccountPERIOD YEARPERIOD NAMEBeginning BalanceClosing BalanceBeginning Balance of Selected PeriodsClosing Balance of Selected Periods
100402019Apr-19960019775211960019214425
100402019May-19775211785203960019214425
100402019Jun-19785203214425960019214425

 

 

How can I obtain these measures Beginning Balance of Selected Periods and Closing Balance of Selected Periods?

 

Thanks.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@hgrangeret try these two measures

 

Start Balance = 
VAR minDate = CALCULATE( MIN( Table2[PERIOD NAME] ), ALLSELECTED( Table2[PERIOD NAME] ) )
RETURN CALCULATE( FIRSTNONBLANK( Table2[Beginning Balance], 1), FILTER( ALLEXCEPT( Table2, Table2[Account] ), Table2[PERIOD NAME] = minDate ) )
End Balance = 
VAR maxDate = CALCULATE( MAX( Table2[PERIOD NAME] ), ALLSELECTED( Table2[PERIOD NAME] ) )
RETURN CALCULATE( LASTNONBLANK( Table2[Closing Balance], 1), FILTER( ALLEXCEPT( Table2, Table2[Account] ), Table2[PERIOD NAME] = maxDate ) )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
parry2k
Super User
Super User

@hgrangeret try these two measures

 

Start Balance = 
VAR minDate = CALCULATE( MIN( Table2[PERIOD NAME] ), ALLSELECTED( Table2[PERIOD NAME] ) )
RETURN CALCULATE( FIRSTNONBLANK( Table2[Beginning Balance], 1), FILTER( ALLEXCEPT( Table2, Table2[Account] ), Table2[PERIOD NAME] = minDate ) )
End Balance = 
VAR maxDate = CALCULATE( MAX( Table2[PERIOD NAME] ), ALLSELECTED( Table2[PERIOD NAME] ) )
RETURN CALCULATE( LASTNONBLANK( Table2[Closing Balance], 1), FILTER( ALLEXCEPT( Table2, Table2[Account] ), Table2[PERIOD NAME] = maxDate ) )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks parry2k,

 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.