- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @BotBot1 ,
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 + PreviousDailyNetBalance
If 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
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good morning @BotBot1
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
no worries I understand.
What results did you get without using SELECTEDVALUE? What is the reason for adding SELECTEDVALUE?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @tamerj1 ,
The DAX says "Cannot find name [glt_trdate]" with the following message when the measure is added to the table:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh! My mistake. Please try
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_Account', ALL ( 'Date' ) )
VAR TableOnAndBefore =
FILTER ( CurrentPeriodTable, 'GL_Account'[glt_trdate] <= CurrentDate )
VAR PreviousDailyNetBalance =
SUMX ( CurrentPeriodTable, 'GL_Account'[Daily Net Balance] )
RETURN
PreviousClosingBalance + PreviousDailyNetBalance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @tamerj1 ,
Thank you for your continued help on this. It is now returning the sum of the daily net balances that are within the financial period.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After swapping the 'Date'[Date] out of the table for the transaction date, 'GL_Account'[glt_trdate], I actually have the Daily Net Balance returning as the DailyClosingBalance:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @BotBot1 ,
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 + PreviousDailyNetBalance
If 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
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @BotBot1
You are sorting the dates on descending order. Are you sure this is the correct order of calculation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 + PreviousDailyNetBalance
However 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One more thing do you really think that it's not worth mentioning that the data os coming from two different tables? Do you really think that relationship are irrelevant and they do not matter? Please provide me with the complete picture to avoid wasting more time and effort.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@BotBot1
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@BotBot1
is [Daily Net Balance] a column or a measure? If measure please advise the dax

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
10-22-2024 06:39 AM | |||
10-23-2024 03:39 AM | |||
05-28-2022 08:10 AM | |||
11-06-2024 10:30 AM | |||
09-08-2024 12:17 PM |