Forum Discussion
Removing column filter context from a measure for a variation
- 4 years ago
Hi vinny1986 ,
Please try the following formula:
Variation = VAR __Year = CALCULATE ( MAX ( dbo_DimTemps[AnneeFinanciere] ), ALLSELECTED ( dbo_DimTemps[AnneeFinanciere] ) ) --to select the max year from my filter-- VAR __Actual = CALCULATE ( [Année], FILTER ( ALLSELECTED ( PV_FactSoldesGL_pourfusion[Type] ), PV_FactSoldesGL_pourfusion[Type] = "Actuel" ), dbo_DimTemps[AnneeFinanciere] = __Year ) --to select the actual from current year (2022)-- RETURN IF ( SELECTEDVALUE ( PV_FactSoldesGL_pourfusion[Type] ) = "Budget" && ISBLANK ( SELECTEDVALUE ( dbo_DimTemps[AnneeFinanciere] ) ) = FALSE, __Actual - [Année] )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi vinny1986 ,
Please try the following formula:
Variation =
VAR __Year =
CALCULATE (
MAX ( dbo_DimTemps[AnneeFinanciere] ),
ALLSELECTED ( dbo_DimTemps[AnneeFinanciere] )
) --to select the max year from my filter--
VAR __Actual =
CALCULATE (
[Année],
FILTER (
ALLSELECTED ( PV_FactSoldesGL_pourfusion[Type] ),
PV_FactSoldesGL_pourfusion[Type] = "Actuel"
),
dbo_DimTemps[AnneeFinanciere] = __Year
) --to select the actual from current year (2022)--
RETURN
IF (
SELECTEDVALUE ( PV_FactSoldesGL_pourfusion[Type] ) = "Budget"
&& ISBLANK ( SELECTEDVALUE ( dbo_DimTemps[AnneeFinanciere] ) ) = FALSE,
__Actual - [Année]
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I added IF condition to show actuals on the Actual side two for two years.
Thanks a lot for your help!
Variation =
var __Year = calculate(max(dbo_DimTemps[AnneeFinanciere]),ALLSELECTED(dbo_DimTemps[AnneeFinanciere]))
-- Max selected year --
var __Actual = calculate('Table Measure'[Année],
filter(ALLSELECTED(PV_FactSoldesGL_pourfusion[Type]),
PV_FactSoldesGL_pourfusion[Type]="Actuel"),dbo_DimTemps[AnneeFinanciere] = __Year)
-- Actual current year --
var __Actual_LY = calculate('Table Measure'[Année],
filter(ALL(dbo_DimTemps[AnneeFinanciere]), dbo_DimTemps[AnneeFinanciere] = __Year -1)
)
-- Actual Last year --
var __Actual_2YA = calculate('Table Measure'[Année],
filter(ALL(dbo_DimTemps[AnneeFinanciere]), dbo_DimTemps[AnneeFinanciere] = __Year -2)
)
-- Actual 2 years ago --
return
if(SELECTEDVALUE(PV_FactSoldesGL_pourfusion[Type]) = "Actuel" && SELECTEDVALUE(dbo_DimTemps[AnneeFinanciere]) = __Year,
__Actual - __Actual_LY,
--variation actual year vs actual year -1 --
if(SELECTEDVALUE(PV_FactSoldesGL_pourfusion[Type]) = "Actuel" && SELECTEDVALUE(dbo_DimTemps[AnneeFinanciere]) = __Year-1,
__Actual_LY - __Actual_2YA,
--variation actual year -1 vs actual year -2 --
if(SELECTEDVALUE(PV_FactSoldesGL_pourfusion[Type]) = "Budget" && isblank( SELECTEDVALUE(dbo_DimTemps[AnneeFinanciere])) = false,
__Actual - 'Table Measure'[Année])
--variation actual year vs budget --
)
)