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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

 

Screenshot_16.png

 

scenario 1 : If I did not select any Date value from Date Filter, Then the Output is

 

Screenshot_13.png

 

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

Screenshot_14.png

2 ACCEPTED SOLUTIONS
tex628
Community Champion
Community Champion

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

View solution in original post

tex628
Community Champion
Community Champion

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

View solution in original post

7 REPLIES 7
tex628
Community Champion
Community Champion

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
Anonymous
Not applicable

@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.

 

 

vengadeshpalani_0-1597131916433.png

 

tex628
Community Champion
Community Champion

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
Anonymous
Not applicable

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

vengadeshpalani_1-1597135434209.png

 

 

tex628
Community Champion
Community Champion

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
amitchandak
Super User
Super User

@Anonymous , 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

Anonymous
Not applicable

@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

 

 

Screenshot_18.png

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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