What I am trying to do is look at Monthly Headcount Trend (Variance %) by Billable, Non-Billable and Total. My approach to identify change % is : (Current Month - Previous Month) / Previous Month. Since, it will be showing multiple months data in a tabular form, so I used the following formula for Variance %
(SUM( CASE WHEN
Billable Flag
='Y' THEN IFNULL(
Headcount
,0) END )
LAG( SUM( CASE WHEN
Billable Flag
='Y' THEN IFNULL(
Headcount
,0) ELSE 0 END )) over( Partition by
Cost Center Family
ORDER BY MONTH(
Date
))
) * 1.
/
LAG( SUM( CASE WHEN
Billable Flag
='Y' THEN IFNULL(
Headcount
,0) ELSE 0 END )) over( Partition by
Cost Center Family
ORDER BY MONTH(
Date
))
This formula works fine at row level but at Grand Total level the Variance % shows incorrect number which is not even close to the actual output. But when I check the formula to see Variance Number by removing the Denominator, the output is correct. Which means it is only creating issue when it is getting divided. But at row level (which is Cost Center Family wise), the Variance % is showing correct output.
In the above image, I have mentioned 2 Grand Total. The Expected is what should ideally come but I am getting the output as What is Showing.
I am using Pivot Table if that helps.
Also sharing the workbook for referance. Looking for some help here