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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Planda
Frequent Visitor

Closing and opening balance with cashflow

Hi,

 

I am having quite a big trouble of calculating cash flow in my report.

 

I have this situation:

 2016-012016-022016-032016-042016-052016-062016-072016-082016-092016-102016-112016-12
Opening cash balance25830002092389150727676695515613230240542294112160152970323522053241127753174260
Cashflow-490611-585113-740321-6108232867922-729942-692583-898294-4827033892243-938515-926028
Closing cash balance20923891507276766955156132302405422941121601529703235220532411277531742602248232

 

I have a static number of 2583000 on January 2016 as an opening cash balance. I have a measure created from Cashflow, that is calculated from accounting book table.  

 

In theory I should have these two measures:

 

   1) Closing cash balance = Opening cash balance + Cashflow

   2) Opening cash balance = CALCULATE([Closing cash balance],PREVIOUSMONTH('Date'[Date]))

 

But I am getting circular dependency error. It is understandable, but I can't figure out how to make this situation work.

 

Anyone has experience with this and can suggest some solution?

 

Thank you

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Planda 

According to your description, I think you should first do some transformation on the data then create measures to achieve this, you follow my steps:

  1. You can refer to the document that amitchandak posted to transpose this data in Power query editor, then get the data like this(If you don’t understand, you can learn from the pbix file I posted below):

v-robertq-msft_0-1608715452102.png

 

  1. Create a calculated column:
Month = MONTH('Table'[Date])
  1. Create two measures:
Closing cash balance =

var _cashflow=CALCULATE(SUM('Table'[Cashflow]),FILTER(ALL('Table'),[Month]<=MAX([Month])))

return

2583000+_cashflow
Opening cash =

var _value=CALCULATE([Closing cash balance],FILTER(ALL('Table'),[Month]=MAX([Month])-1))

return

IF(MAX('Table'[Month])=1,2583000,_value)
  1. Create a table chart and place columns and measures like this:

v-robertq-msft_1-1608715452123.png

 

And you can get what you want.

You can download my test pbix file here

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-robertq-msft
Community Support
Community Support

Hi, @Planda 

According to your description, I think you should first do some transformation on the data then create measures to achieve this, you follow my steps:

  1. You can refer to the document that amitchandak posted to transpose this data in Power query editor, then get the data like this(If you don’t understand, you can learn from the pbix file I posted below):

v-robertq-msft_0-1608715452102.png

 

  1. Create a calculated column:
Month = MONTH('Table'[Date])
  1. Create two measures:
Closing cash balance =

var _cashflow=CALCULATE(SUM('Table'[Cashflow]),FILTER(ALL('Table'),[Month]<=MAX([Month])))

return

2583000+_cashflow
Opening cash =

var _value=CALCULATE([Closing cash balance],FILTER(ALL('Table'),[Month]=MAX([Month])-1))

return

IF(MAX('Table'[Month])=1,2583000,_value)
  1. Create a table chart and place columns and measures like this:

v-robertq-msft_1-1608715452123.png

 

And you can get what you want.

You can download my test pbix file here

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Planda , first of all you need to transpose this data

Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/

pivot/unpivot - https://radacad.com/pivot-and-unpivot-with-power-bi

 

If need conver month to date

Date = Date(left([Month],4), right([month],2),1)

 

You can use date in place of month.

Create a measure like

 

Closing cash balance =
var _min = minx(all(Table), Table[Month]) //or use date
return
calculate(sum(Table[Opening cash balance]), filter(Table, Table[Month] =_min)) - calculate(sum(Table[Cashflow]), filter(Table, Table[Month] <=max(Table[Month)))

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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