
VAR StartYear = 2009
VAR EndYear = 2017
VAR Sector = SELECTEDVALUE(COMPANIES[SECTOR])  -- Get the current sector value

VAR BeginningValue = 
    CALCULATE(
        SUM(STATEMENTDATA[VALUE]),
        STATEMENTLINES[LINEITEM] = "REVENUE",
        DATES[Year] = StartYear,
        STATEMENTDATA[COMPANYID] = SELECTEDVALUE(COMPANIES[COMPANYID]),
        COMPANIES[SECTOR] = Sector  -- Ensure filtering by sector
    )

VAR EndingValue = 
    CALCULATE(
        SUM(STATEMENTDATA[VALUE]),
        STATEMENTLINES[LINEITEM] = "REVENUE",
        DATES[Year] = EndYear,
        STATEMENTDATA[COMPANYID] = SELECTEDVALUE(COMPANIES[COMPANYID]),
        COMPANIES[SECTOR] = Sector  -- Ensure filtering by sector
    )

VAR NumberOfYears = EndYear - StartYear

RETURN
    IF(
        BeginningValue > 0 && NumberOfYears > 0,
        (EndingValue / BeginningValue) ^ (1 / NumberOfYears) - 1,
        BLANK()
    )
