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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
han_rj
Helper III
Helper III

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

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.

@v-zhengdxu-msft , 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

 

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 @v-zhengdxu-msft 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.