Forum Discussion
Daily Balance Calculation
- 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
Hi Anonymous
You are sorting the dates on descending order. Are you sure this is the correct order of calculation?
- Anonymous3 years agoNot 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- tamerj13 years agoCommunity 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- Anonymous3 years agoNot applicable
Hi tamerj1,
Thanks for this.I adjusted the DAX to the following (as it was not picking up the 'GL_Account'[ClosingBalance] and 'Date'[Date] in TableOnAndBefore):
DailyClosingBalance = VAR CurrentDate = MAX ( 'Date'[Date] ) VAR CurrentPeriodTable = CALCULATETABLE ( 'GL_Period', ALLEXCEPT ( 'GL_Period', 'GL_Period'[FinancialPeriod])) VAR CurrentClosingBalance = MINX ( CurrentPeriodTable, SELECTEDVALUE('GL_Account'[ClosingBalance]) ) VAR TableOnAndBefore = FILTER ( CurrentPeriodTable, SELECTEDVALUE('Date'[Date]) <= CurrentDate ) VAR PreviousDailyNetBalance = SUMX ( TableOnAndBefore, [Daily Net Balance] ) RETURN CurrentClosingBalance + PreviousDailyNetBalanceHowever this is now returning the following:
It is doing the row's ClosingBalance + Daily Net Balance, but it needs to be the previous financial periods closing balance + the sum of the daily net balances up to the rows date, e.g. 01/03/2023: 12,248,807.97 - 5,990.75 - 222,586.15 = 12,020,231.07