cancel
Showing results for
Search instead for
Did you mean:  Helper III

## Opening & Closing Balance by category

Hi All,

I have attached pbix file:

https://www.dropbox.com/s/g9el2fm4o637gl2/Open%20%26%20Closeing%20Balance.pbix?dl=0

I have data like below table. By using this table i want to create "Opening & Closing Balance". Expected output was shown in below screenshot scenario 1 : If I did not select any Date value from Date Filter, Then the Output is scenario 2 : If Date filter is from 02/27/2020 to 03/31/20202 Then Output is:

Note: Opening Balance for Product sales is sum(opening Balance) where Date is  02/27/2020. Because Product Sales Min Date is 02/27/2020 so -175584.24+0 = -175584.24 2 ACCEPTED SOLUTIONS  Super User II

I have no working file 🙂

Give this a try, if I'm thinking about this correctly this should return the totals you're looking for:

``````Opening Balance =
VAR P_date = IF(SELECTEDVALUE(Table[Posting Date]) = BLANK() , MIN(Table[Posting Date]) , SELECTEDVALUE(Table[Posting Date]))
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] < P_Date)``````
``````Closing Balance =
VAR P_date = IF(SELECTEDVALUE(Table[Posting Date]) = BLANK() , MAX(Table[Posting Date]) , SELECTEDVALUE(Table[Posting Date]))
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] <= P_Date)``````

Let me know how it goes!

/ J

Connect on LinkedIn  Super User II

There are a few different ways and it working depends on the structure of the matrix. But lets try the easiest first, adding a "+0".

``````Opening Balance =
VAR P_date = IF(SELECTEDVALUE(Table[Posting Date]) = BLANK() , MIN(Table[Posting Date]) , SELECTEDVALUE(Table[Posting Date]))
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] < P_Date) + 0``````

Let me know if it works.

/ J

Connect on LinkedIn
7 REPLIES 7  Super User II

Try this,

``````Opening Balance =
VAR P_date = SELECTEDVALUE(Table[Posting Date])
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] < P_Date)``````
``````Closing Balance =
VAR P_date = SELECTEDVALUE(Table[Posting Date])
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] <= P_Date)``````

Let me know how it goes.

/ J

Connect on LinkedIn  Helper III

@tex628 , Thanks for response,

Every things looks good.. Except total value..

i have created Master Calendar & connected with Posting Date. Added calendar date in filter & table.

Can you Please share the working File.   Super User II

I have no working file 🙂

Give this a try, if I'm thinking about this correctly this should return the totals you're looking for:

``````Opening Balance =
VAR P_date = IF(SELECTEDVALUE(Table[Posting Date]) = BLANK() , MIN(Table[Posting Date]) , SELECTEDVALUE(Table[Posting Date]))
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] < P_Date)``````
``````Closing Balance =
VAR P_date = IF(SELECTEDVALUE(Table[Posting Date]) = BLANK() , MAX(Table[Posting Date]) , SELECTEDVALUE(Table[Posting Date]))
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] <= P_Date)``````

Let me know how it goes!

/ J

Connect on LinkedIn  Helper III

Thank you @tex628 .. Its Working...

I got what i want. thank you so much

one more request.. how can i replace blank value by Zero   Super User II

There are a few different ways and it working depends on the structure of the matrix. But lets try the easiest first, adding a "+0".

``````Opening Balance =
VAR P_date = IF(SELECTEDVALUE(Table[Posting Date]) = BLANK() , MIN(Table[Posting Date]) , SELECTEDVALUE(Table[Posting Date]))
Return
CALCULATE(SUM(Table[Amount]) , ALLSELECTED(Calendar[Date]) , Calendar[Date] < P_Date) + 0``````

Let me know if it works.

/ J

Connect on LinkedIn  Super User IV

@vengadeshpalani , not very clear. is the balance of A going to C.

Can you share sample data and sample output in table format?

refer :closingbalancemonth ,closingbalancequarter, closingbalanceyear

https://www.youtube.com/watch?v=yPQ9UV37LOU

firstnonblankvalue and lastnonblankvalue

https://www.linkedin.com/pulse/five-recent-power-bi-functions-you-should-use-more-often-amit-chandak

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!  Helper III

@amitchandak , Thanks for the reply

if i select Date range from 02/27/2020 Then

Sales-A opening balance for 02/27/2020 is -175583.24.... 03/03/2020 opening balance is -175583.24 + (-5950.00) =-181534.24 etc...

Sales-B opening balance for 02/27/2020 is 0

Sales-C opening balance for 03/09/2020 is 0

Sales-D opening balance for 03/24/2020 is 0..... 03/30/2020 opening balance is -62874

Sales-A, Sales-B, Sales-C, Sales-D are catergrozied under Product Sales... so Product Sales Minimum Date is 02/27/2020..

Product Sales opening balance is sum of opening balance where Date is 02/27/2020   ## Helpful resources

Announcements #### Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group! #### Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks Top Solution Authors
Top Kudoed Authors
Users online (14,030)