Forum Discussion
Daily Balance Calculation
Hi,
I am trying to get the daily closing balance of my data. I currently have dates given by 'Date'[Date] showing the working days (weekends are blank) of debits and credits being logged.
At the moment, I only have one value for the closing balance each month, which is the 'GL_Period'[FinancialPeriod] date, but I have the daily net debit/credit balance within a measure called [Daily Net Balance] to use to calculate the daily closing balance (see below). The closing balance is given in 'GL_Account'[ClosingBalance].
So what I need is for the Daily Closing Balance to be the previous financial period's closing balance and to have added all daily net balances up to the date being looked at.
E.g. For 02/03/2023: Closing Balance = 12,248,807.97 - 5,990.75 - 222,586.15 + 26,775.00
Please see the below Excel for what the ideal results would be like:
Thank you.
- Anonymous3 years ago
Hi Anonymous ,
Please update the formula of measure as below and check if it can return the expected result...
DailyClosingBalance = VAR CurrentDate = SELECTEDVALUE ( 'GL_Account'[glt_trdate] ) VAR CurrentPeriod = SELECTEDVALUE ( 'GL_Period'[id_glperiod] ) VAR PreviousPeriod = MAXX ( FILTER ( ALLSELECTED ( 'GL_Period'[id_glperiod] ), 'GL_Period'[id_glperiod] < CurrentPeriod ), 'GL_Period'[id_glperiod] ) VAR PreviousClosingBalance = CALCULATE ( MAX ( 'GL_Account'[ClosingBalance] ), FILTER ( ALLSELECTED ( 'GL_Period' ), 'GL_Period'[id_glperiod] = PreviousPeriod ), ALL ( 'Date' ) ) VAR PreviousDailyNetBalance = SUMX ( FILTER ( ALLSELECTED ( 'GL_Account' ), 'GL_Account'[glt_trdate] <= CurrentDate ), 'GL_Account'[Daily Net Balance] ) RETURN PreviousClosingBalance + PreviousDailyNetBalanceIf the above one can't help you, please provide some raw data in your table 'GL_Account' and 'GL_Period' (exclude sensitive data) with Text format and your expected result with backend logic and special examples? By the way, is there any relationship between these two tables? If yes, please provide the related info. It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
19 Replies
- tamerj1Community Champion
Good morning Anonymous
Please try the following. Probably won't work and sure not optimum but there is a chance that it would. If not, please let me know if we can connect on Saturday (any time before 2:00pm Dubai time)DailyClosingBalance = VAR CurrentDate = SELECTEDVALUE ( 'GL_Account'[glt_trdate] ) VAR CurrentPeriod = SELECTEDVALUE ( 'GL_Period'[id_glperiod] ) VAR PreviousPeriod = MAXX ( FILTER ( ALLSELECTED ( 'GL_Period'[id_glperiod] ), 'GL_Period'[id_glperiod] < CurrentPeriod ), 'GL_Period'[id_glperiod] ) VAR PreviousClosingBalance = CALCULATE ( MAX ( 'GL_Account'[ClosingBalance] ), 'GL_Period'[id_glperiod] = PreviousPeriod, ALL ( 'Date' ) ) VAR CurrentPeriodTable = CALCULATETABLE ( 'GL_Period', ALL ( 'Date' ) ) VAR TableOnAndBefore = FILTER ( CurrentPeriodTable, 'GL_Period'[glt_trdate] <= CurrentDate ) VAR PreviousDailyNetBalance = SUMX ( CurrentPeriodTable, 'GL_Account'[Daily Net Balance] ) RETURN PreviousClosingBalance + PreviousDailyNetBalance- AnonymousNot applicable
Hi tamerj1 ,
Thanks again for your help, it's really appreciated. I added SELECTEDVALUE to the 'GL_Period'[glt_trdate] in the TableOnAndBefore variable but it has returned the same values as that in the Daily Net Balance measure.
Unfortunately I cannot share much more information, i.e. have a call with you/sample file as the overwhelming majority of the dataset contains confidental information, but is there anything I can do to help with reworking the DAX to help you in any way? Thank you
- tamerj1Community Champion
Anonymous
no worries I understand.
What results did you get without using SELECTEDVALUE? What is the reason for adding SELECTEDVALUE?
- tamerj1Community Champion
Hi Anonymous
You are sorting the dates on descending order. Are you sure this is the correct order of calculation?- AnonymousNot applicable
Hi tamerj1 ,
Yes I already had in the model a variable for debits/credits linked to the Date, so my Daily Net Balance was just:
Daily Net Balance = CALCULATE(SUM('GL_Account'[glt_amt_doc]), GROUPBY('Date', 'Date'[date])).
In terms of the closing balance, this is correct also. It is the closing balance whereby it stops at the FinancialPeriod date, i.e. 12,177,354.57 is the closing balance today and whatever the closing balance is on 31st March, the closing balance will show as this value for all dates 25th February 2023 - 31st March 2023. Thanks- tamerj1Community Champion
Anonymous
This should work as either calculated column or measure.
Closing Balance Final = VAR CurrentDate = MAX ( 'Table'[Date] ) VAR CurrentPeriodTable = CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[FinancialPeriod] ) ) VAR CurrentClosingBalance = MINX ( CurrentPeriodTable, 'Table'[ClosingBalance] ) VAR TableOnAndBefore = FILTER ( CurrentPeriodTable, 'Table'[Date] <= CurrentDate ) VAR PreviousDailyNetBalance = SUMX ( TableOnAndBefore, 'Table'[DailyNetBalance] ) RETURN CurrentClosingBalance + PreviousDailyNetBalance