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
Mr_Glister
Advocate II
Advocate II

AVERAGE of OPENINGBALANCEYEAR of multiple years

Hi,

I have a very large dataset that I connect to via Direct Query.

 

In its simplest form, my problem is this. 

I am using OPENINGBALANCEYEAR to retreive the first value of the year to perform a calculation based on it.

This could be [% of new stores added in period] for example.

If I only look at one year, this works quite well. But when I want to look at multiple years aggregated, I would rather have my calculation use the AVERAGE of the results of OPENINGBALANCEYEAR of the different years.

 

I'm providing some sample data below.

 

Let Table1 be my data.

Table1.PNG

 

Let the table below be the normal behaviour of OPENINGBALANCEYEAR when the table has years as the filter context in the rows.

Measure.PNG

The table below is what I'd like to achieve when I remove the Year from the rows. 

(OPENINGBALANCEYEAR would just return 50 and 101)

Outcome.PNG

 

Can somebody help me with this?

4 REPLIES 4
Mr_Glister
Advocate II
Advocate II

Thanks @v-stephen-msft  and @amitchandak !

I'm afraid I've made my sample data little more simplistic than the problem actually is.

Would your solutions also work when I in fact use OPENINGBALANCEMONTH? It is really the opening balance of months that I want to average. For example "the average of the opening balances of February" from 2018-2021.

Hi @Mr_Glister ,

 

Sorry for taking so long to reply to you, OPENINGBALANCEMONTH does not seem to work here.

 

 

Best Regards,

Stephen Tao

 

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

v-stephen-msft
Community Support
Community Support

Hi @Mr_Glister ,

 

Here's my solution.

First measure:

Opening Balance =
CALCULATE (
    SUM ( 'Table1'[Number of stores] ),
    FILTER ( 'Table1', MONTH ( [Date] ) = 1 && DAY ( [Date] ) = 1 )
)

16.png

 

Second measure:

Opening Balance 2 =
AVERAGEX ( 'Table1', [Opening Balance] )

17.png

 

 

 

Best Regards,

Stephen Tao

 

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

 

amitchandak
Super User
Super User

@Mr_Glister , Try a measure like

 

calculate(AverageX(Table,calculate( Firstnonblankvalue('Date'[Date], sum(Table[Stores]))) ), filter(allselected('Date'), 'Date'[Year] = max('Date'[Year])))

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.