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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
han_rj
Helper IV
Helper IV

Nested Calculation item not working

I have created a calculation item for This Year and Prior Year and wanted to calculate Variance for it.

But the varaince calculation item is not working 

Variance = CALCULATE(SELECTEDMEASURE(),Time_Period[Time_Period_Grp] = "TY") -  CALCULATE(SELECTEDMEASURE(),Time_Period[Time_Period_Grp] = "LY")

 

han_rj_0-1732802071718.png

 

7 REPLIES 7
johnt75
Super User
Super User

A calculation group is only called once per measure, so you cannot nest them like this. You would either need to have the variance in a separate calculation group or replicate the time intelligence logic in the TY & LY calculation items.

Thank You for responding, I tried both ways did'nt work

Try

Variance =
VAR ThisYear =
    CALCULATE ( SELECTEDMEASURE (), DATESYTD ( 'Date'[Date] ) )
VAR LastYear =
    CALCULATE (
        SELECTEDMEASURE (),
        DATEADD ( DATESYTD ( 'Date'[Date] ), -1, YEAR )
    )
VAR Result = ThisYear - LastYear
RETURN
    Result
Anonymous
Not applicable

Hi @han_rj 

 

Could you please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

 

Best Regards

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

@Anonymous , Thank You for responding

 

This is the sample data

han_rj_0-1732891727842.png

 

Calculation Items used

Last_Year = CALCULATE(SELECTEDMEASURE(),'Table'[Last_Year_Ind] = "Y")
This_Year = CALCULATE(SELECTEDMEASURE(),'Table'[This_Year_Ind] = "Y")
YOY = CALCULATE(SELECTEDMEASURE(),'Table'[This_Year_Ind] = "Y") -
CALCULATE(SELECTEDMEASURE(),'Table'[Last_Year_Ind] = "Y")
 
Current Results
han_rj_1-1732891810923.png

Expected

I want variance for the current year only

han_rj_2-1732892032760.png

 

Anonymous
Not applicable

Hi @han_rj 

 

Please try this:

First of all, Create a measure:

Measure = SUM('Table'[Sales])

Then add a calculation group:

Last_Year = CALCULATE(SELECTEDMEASURE(),'Table'[Last_Year_Ind] = "Y")
This_Year = CALCULATE(SELECTEDMEASURE(),'Table'[This_Year_Ind] = "Y")
YOY =
CALCULATE ( SELECTEDMEASURE (), 'Table'[This_Year_Ind] = "Y" )
    - CALCULATE ( SELECTEDMEASURE (), 'Table'[Last_Year_Ind] = "Y" )

vzhengdxumsft_0-1733121353694.png

Finally, create a Matrix and the result is as follow:

vzhengdxumsft_1-1733121427114.png

 

 

Best Regards

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

Thank You @Anonymous for responding the format I am looking for is like this

CY, TY label and the Year.

han_rj_0-1733121751663.png

If we exclude the Year in the column we get the correct results but when we add Year to the column the variance is off like this

han_rj_1-1733121850995.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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