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

Logical error in calculating value for previous fiscal year

Hi all,

 

I'm trying to calculate % variance for a value and leveraging the filter context to decide which year to calculate the variance w.r.t. previous year for. This seems so intuitive it should work and I'm sure it's a silly thing I'm missing. Any ideas?

 Variance in Emissions % Year-on-Year =
VAR EmissionsOfPreviousYear =
    CALCULATE (
        //Calculates previous year's Emissions based on filter context
        SUM ( 'Inventory Data'[Value] ),
        FILTER (
            'Master Data Elements',
            'Master Data Elements'[Summary Classification] = "(tCO2-e)"
        ),
        FILTER (
            'Calendar Table'[Fiscal Year],
            'Calendar Table'[Fiscal Year] = [Previous fiscal year] // this is what doesn't seem to work
        )
    )
RETURN
    // return the %variance from previous year
    DIVIDE (
        Metrics[Total (tCO2-e)] - EmissionsOfPreviousYear,
        EmissionsOfPreviousYear
    )


For your information:
Previous fiscal year = MAX('Calendar Table'[Fiscal Year])-1
And,
 
Total (tCO2-e) =
CALCULATE (
SUM ( 'Inventory Data'[Value] ),
'Master Data Elements'[Summary Classification] = "(tCO2-e)"
)
1 ACCEPTED SOLUTION

Hi @rushi 
Please try

=
VAR TotaltCO2e = [Total (tCO2-e)]
VAR CurrentYear =
    MAX ( 'Calendar Table'[Fiscal Year] )
VAR PreviousYear = CurrentYear - 1
VAR EmissionsOfPreviousYear =
    CALCULATE (
        SUM ( 'Inventory Data'[Value] ),
        'Master Data Elements'[Summary Classification] = "(tCO2-e)",
        'Calendar Table'[Fiscal Year] = PreviousYear
    )
RETURN
    DIVIDE ( TotaltCO2e - EmissionsOfPreviousYear, EmissionsOfPreviousYear )

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi @rushi 

please try

=
VAR TotaltCO2e = [Total (tCO2-e)]
VAR PreviousYear = [Previous fiscal year]
VAR EmissionsOfPreviousYear =
    CALCULATE (
        //Calculates previous year's Emissions based on filter context
        SUM ( 'Inventory Data'[Value] ),
        'Master Data Elements'[Summary Classification] = "(tCO2-e)",
        'Calendar Table'[Fiscal Year] = PreviousYear // this is what doesn't seem to work
    )
RETURN
    // return the %variance from previous year
    DIVIDE (
        TotaltCO2e - EmissionsOfPreviousYear,
        EmissionsOfPreviousYear
    )
rushi
Frequent Visitor

Thanks @tamerj1 ,

While the solution works, it doesn't hold true once the vizual is drilled down into quarters. How can I make the measure so that it holds true for when the visualization has year view but also when it is drilled down into quarter view?

@rushi 
Does the [Previous fiscal year] measure work at quarter level? Waht is the code of this measure?

rushi
Frequent Visitor

I do not know how to calculate the previous Fiscal year from the current fiscal year in context.

Hi @rushi 
Please try

=
VAR TotaltCO2e = [Total (tCO2-e)]
VAR CurrentYear =
    MAX ( 'Calendar Table'[Fiscal Year] )
VAR PreviousYear = CurrentYear - 1
VAR EmissionsOfPreviousYear =
    CALCULATE (
        SUM ( 'Inventory Data'[Value] ),
        'Master Data Elements'[Summary Classification] = "(tCO2-e)",
        'Calendar Table'[Fiscal Year] = PreviousYear
    )
RETURN
    DIVIDE ( TotaltCO2e - EmissionsOfPreviousYear, EmissionsOfPreviousYear )
rushi
Frequent Visitor

Ah yes! That was simple don't know why I missed that. Thank you @tamerj1 ! It WORKS! Sort of like a manual implementation of SAMEPERIODLASTYEAR.

rushi
Frequent Visitor

It could be that when I try to view  "Variance in Emissions % Year-on-Year" in  a table with fiscal year, for each row, the filter context gets confused between whether to filter by the fiscal year in row or [Previous fiscal 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.