Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX Measure for opening balance

Hello all,

 

I have this measure which calculates the closing balance per filtered period:

 

RestBudgetAcrossYears =

var Planned_budget = sum(DIA_PBI_SAP_ZEITPROJECTAUFGABEN[projectitembudgettime])
var maxSelectedDate = Max('Date'[Date])
var AllActualWorkDoneBeforeCurrentDate =
CALCULATE(
SUM(DIA_PBI_SAP_ZEITPROJECTLEISTUNGAUSSAP[Verrechenbar]),
FILTER(ALL('Date'[Date]), [Date] <= maxSelectedDate)
)
return
if ([Rapportierte Zeit] <> BLANK(),Planned_budget-AllActualWorkDoneBeforeCurrentDate)
 
I would like to adjust the measure so it gives me the opening balance for each period.
 
This is what the result should look like (the measure above gives RestBudgetAcrossYears, but I want a measure to calculate OpeningBudgetAcrossYears):
 
JahrMonatOpeningBudgetAcrossYearsRapportierte ZeitVerrechenbarRestBudgetAcrossYears
2017Jan187403.120510538.996311486.580817185916.5397
2017Feb185916.53979452.0160571541.166325184375.3734
2017Mar184375.373411194.532991455.316661182920.0567
2017Apr182920.05678475.1319831081.632323181838.4244
2017May181838.424410471.298321466.866548180371.5578
2017Jun180371.55789868.0323231369.116319179002.4415
2017Jul179002.44158198.336651050.43932177952.0022
2017Aug177952.00229148.8493351222.983268176729.0189
2017Sep176729.01899680.2163111626.130313175102.8886
2017Oct175102.88869516.422951812.091642173290.797
2017Nov173290.79711581.965621969.362323171321.4347
2017Dec171321.43478226.3309841447.260661169874.174
2018Jan169874.174169874.1741553.776327168320.3977
2018Feb168320.39779490.4833051483.083325166837.3143
 
Could someone kindly assist with this?
 
Many thanks.
9 REPLIES 9
v-yangliu-msft
Community Support
Community Support

Hi    @Anonymous  ,

Here are the steps you can follow:

1. You can define this data to form a variable.

2. Create calculated column.

 

OpeningBudgetAcrossYears_column =

var _ definition = CALCULATE(MAX('Table'[RestBudgetAcrossYears]),FILTER('Table','Table'[Index]=1))

var _1=CALCULATE(SUM('Table'[RestBudgetAcrossYears]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))

return IF([Index]=1,_ definition -0,_1)

 

3. Result:

v-yangliu-msft_0-1609229649283.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi Liu,

I'm afraid that the Index part of your suggested solution doesn't work.

I've created the index column based on a date column. However, when I refresh the query from the source, and new lines are populated with the same date as the existing lines, then the indexing is messed up, and is no longer in order.

Do you have another solution?

Many thanks.

Hi  @Anonymous ,

For index confusion, you can do this:

1. You can create a calculated column to connect [Jahr] and [Monat]

Month & Year = 'Table'[Jahr]&"-"&'Table'[Monat]

Result:

v-yangliu-msft_0-1609836440728.png

2. Use Column tools to convert the new column Month & Year to date

v-yangliu-msft_1-1609836440733.png

3. Create calculated column and use rankx function to build index.

index =
RANKX('Table','Table'[Month & Year],,ASC)

4. Create measure.

OpeningBudgetAcrossYears_column =
var _0= CALCULATE(MAX('Table'[RestBudgetAcrossYears]),FILTER('Table','Table'[index]=1))
var _1=CALCULATE(SUM('Table'[RestBudgetAcrossYears]),FILTER('Table','Table'[index]=EARLIER('Table'[index])-1))
return IF([index]=1,_0-0,_1)

Result:

2020.1.5.12132.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yangliu-msft
Community Support
Community Support

Hi    @Anonymous ,

It won't change,the index column continues

You can do this, create measure.

OpeningBudgetAcrossYears_measure = var _1=CALCULATE([RestBudgetAcrossYears],FILTER('Table','Table'[Index]=max('Table'[Index])-1)) return IF([Index]=1,187403.12-0,_1)

 

If my answer is not what you need, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hi Liu

The very first opening balance is not always 187403.12. How can I please change the measure to reflect this?

Thanks.

v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous  ,

Here are the steps you can follow:

1. Enter power query through transform data and select add column --- index column --- from 1 to generate the index

v-yangliu-msft_0-1608782892713.jpeg

2. Create calculated column.

OpeningBudgetAcrossYears_column =
var _1=CALCULATE(SUM('Table'[RestBudgetAcrossYears]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
return IF([Index]=1,187403.12-0,_1)

3. Result:

v-yangliu-msft_1-1608782892718.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi Liu,

Thanks for your response.

 

A couple of a questions:

- The 'RestBudgetAcrossYears' values are actually created through a measure, and do not exist in the table/query. So, the 187403.12 is not fixed. How could I change the DAX measure in order to reflect this?

 

- I've sorted my data in the table based on the date column ascending (the real table has entries based on dates), and then created the index column. What will happen when the data is refreshed in the future, and more entries are added to the existing dates in the table?

 

Looking forward to hearing back from you.

 

Best wishes.

 

Anonymous
Not applicable

Hi @amitchandak 

 

the column 'OpeningBudgetAcrossYears' is missing. I created the example above in Excel.

 

So, it should bring back:

first row: Planned_budget minus AllActualWorkDoneBeforeCurrentDate = 187403.12 - 0 = 187403.12

second row: RestBudgetAcrossYears for the previous period = 185916.53

third row: RestBudgetAcrossYears for the previous period = 184375.37

and so on...

 

If you have another way of achieving the same results that'd also be great.

 

Thanks.

amitchandak
Super User
Super User

@Anonymous , Not very clear with you data, what is missing and what you want to get. Usually we have rebuild opening budget with help first openining budget and cumulative +/- of in and out amount

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.