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
I am trying to be as helpful as possible with my limited knowledge of DAX. I am new to this, which is why I am asking the forum. Also, I have the tables referenced in the original post.
'Date'[Date] -> 'GL_Account'[glt_trdate], which is the transaction date.
'Company'[kco] -> 'GL_Account'[kco], which is 2 companies codes, 22 and 30, referencing the 2 companies in the dataset.
'GL_BusinessUnit'[id_glelement] -> 'GL_Account'[id_glelement], which have bank codes for the different divisions of the 2 companies.
'GL_Period'[id_glperiod] -> 'GL_Account'[id_glperiod], the FinancialPeriod in yyyy-mm-dd format.
This would be a calculated column.
But please, I am trying to be helpful. If I am not being clear, just ask away as I do not know what is required. Thank you.
Anonymous
This should be a calculated column
DailyClosingBalance =
VAR CurrentDate = 'GL_Account'[glt_trdate]
VAR CurrentPeriod = 'GL_Account'[id_glperiod]
VAR TableOnAndBefore =
FILTER ( 'GL_Period', 'GL_Period'[glt_trdate] <= CurrentDate )
VAR CurrentPeriodTable =
FILTER ( TableOnAndBefore, 'GL_Account'[id_glperiod] = CurrentPeriod )
VAR PreviousDailyNetBalance =
SUMX ( CurrentPeriodTable, 'GL_Account'[Daily Net Balance] )
VAR PreviousPeriodTable =
TOPN (
1,
FILTER ( TableOnAndBefore, 'GL_Account'[id_glperiod] < CurrentPeriod ),
'GL_Account'[id_glperiod]
)
VAR PreviousClosingBalance =
MAXX ( PreviousPeriodTable, 'GL_Account'[ClosingBalance] )
RETURN
PreviousClosingBalance + PreviousDailyNetBalance- Anonymous3 years agoNot applicable
Thank you for your help on this. My sincere apologies, but I did not know that you cannot create calculated columns from a live connection. Would it be possible to adjust this as a measure. Sorry again.
- tamerj13 years agoCommunity Champion
Anonymous
No worries.
I'll get back to you tomorrow morning. Meanwhile it would be great if you have a sample file. Have a good night