March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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.
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
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
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
no worries I understand.
What results did you get without using SELECTEDVALUE? What is the reason for adding SELECTEDVALUE?
Hi @tamerj1 ,
The DAX says "Cannot find name [glt_trdate]" with the following message when the measure is added to the table:
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
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.
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:
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
Hi @BotBot1
You are sorting the dates on descending order. Are you sure this is the correct order of calculation?
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:
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
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
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.
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.
@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
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.
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
@BotBot1
is [Daily Net Balance] a column or a measure? If measure please advise the dax
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
16 | |
15 | |
7 | |
7 |
User | Count |
---|---|
37 | |
31 | |
16 | |
16 | |
12 |