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
rfritz
Frequent Visitor

Get value from last year - but apply filter context

Hello Helpers, 

 

I'm trying to calculate the Average Annual Growth Rate (AAGR) for each of our customers, but can't get the filter context applied

 

I have the following data: 

CompanyYearRevenue
A2016350
A2017390
A2018402
A2019489
B20161000
B20171200
B2018900
B2019950
C2016350
C2017333
C2018311
C2019300
C2020320
D2016500
D2017750
D2018375

 

To calculate each year's change rate, I get the previous year's revenue value for each year from which I can then calculate the each year's change rate and finally the AAGR for each company as a separate measure. 

 

CompanyYearRevenueRevenue from Previous YearYearly Growth Rate
A2016350  
A201739035011%
A20184023903%
A201948940222%
B20161000  
B20171200100020%
B20189001200-25%
B20199509006%
C2016350  
C2017333350-5%
C2018311333-7%
C2019300311-4%
C20203203007%
D2016500  
D201775050050%
D2018375750-50%

 

I can get these values as calculated columns, but as soon as I apply a filter, this isn't working any more: calculated columns, once calculated, never change, I've learned. So if I filter out 2016, for example (access the example worksheet here), no company should have any value in growth rate for 2017 (since there is nothing to grow from). And yet, the value stays the same and thus get calculated, too. 

 

So I believe I need to calculate these auxiliary values as a table variable in a measure – and return the AAGR for each company. But from here on, I'm stuck and need help

 

There's one additional consideration that I have to take into account at some point: Since I want to calculate the Average Annual Growth Rate, I can't just filter out any years in the middle (otherwise, it would be an Average Change Rate for the years selected). So filter context should apply to top and bottom years, but not the ones in between. But I think I already found out how to do this, so this is really not my focus. 

 

What I have done in the worksheet is this: 

  • Create calculated columns
  • make a measure that has the Table as variable, gets all the records from first to last year, and returns the number of rows. This seems like the way to go on, but I can't figure out how to go on. 

 

Thus, any help is appreciated, thank you! 

Raphael

 

If I can do anything to make my problem more clear, don't hesitate to tell me. 

3 REPLIES 3
rfritz
Frequent Visitor

I might have found some part of how to do this

The measure below returns each previous year's revenue for each company for a timeframe between two years. So I succeeded in 

  • creating a measure that calculates last year's revenue 
  • and filtering only the years between two explicitly given dates (i.e. passed to the function as an integer). 

 

 

Last Years Revenue = 

VAR firstSelectedYear = FIRSTDATE('Company data'[Year].[Date])

VAR lastSelectedYear = LASTDATE('Company data'[Year].[Date])

VAR LastYearsRevenue = CALCULATE(
        SUM('Company data'[Revenue]),
        SAMEPERIODLASTYEAR('Company data'[Year].[Date]), 
        // This works when it's an integer, but not when it's a variable:
        YEAR('Company data'[Year]) >= 2017, 
        YEAR('Company data'[Year]) < 2019
        // This does not work: 
        // YEAR('Company data'[Year]) >= YEAR(firstSelectedYear), 
        // YEAR('Company data'[Year]) < YEAR(lastSelectedYear)
)
RETURN LastYearsRevenue

 

 

 

The result

rfritz_0-1649152142452.png

But this measure only works with an explicitly given integer – not the actual dates. So what I need to achieve now is to integrate the first and last selected years as variables adjusting to the slicer in the report. 

 

So it feels like having come half way here, at best. Can anyone give me some tips on 

  • how do I integrate the 'firstSelectedYear' / 'lastSelectedYearvariable into the above code
v-yanjiang-msft
Community Support
Community Support

Hi @rfritz ,

Do you mean if you unselect 2018 in the year slicer, the Previous Year's Revenue should be 390(Year2017), but not 402(Year2018)? As well as the AAGR?

vkalyjmsft_0-1649129092845.png

Best Regards,
Community Support Team _ kalyj

Hi @v-yanjiang-msft

yes, exactly. 

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.

Top Solution Authors