Forum Discussion
PERCENTILE inside CALCULATE does not (anymore) recognise data fields
- 10 years ago
Hi Chefe,
I think your best bet is to create a variable to store the value of the current row's [pct] before calling CALCULATE:
Table = VAR dat = DATE ( 2016; 1; 1 ) VAR pct = SUMMARIZE ( ADDCOLUMNS ( CALENDAR ( dat; dat + 99 ); "pct"; [Date] - dat + 1 ); [pct] ) VAR pct_value_calculate = ADDCOLUMNS ( pct; "pct_value"; VAR CurrentPct = [pct] RETURN CALCULATE ( PERCENTILE.INC ( 'Foreign exchange rates'[INDIRECT_FX_CCY_QUOTE]; CurrentPct / 100 ); 'Foreign exchange rates'[FX_CCY] = "USD" ) ) RETURN pct_value_calculateI think a rough explanation is that when CALCULATE triggers a context transition (i.e. row context becomes filter context), any columns within the row context that were created with ADDCOLUMNS (like [pct]) are no longer accessible within the first argument of CALCULATE. This is because 'created columns' have no lineage so cannot be converted to filter context.
This means you can refer to [pct] outside CALCULATE or in one of CALCULATE's filter arguments, but not in CALCULATE's first argument. So the only way I can think of to access the value of [pct] is to save it in a variable before calling CALCULATE.
Owen :)
Hi Chefe,
I think your best bet is to create a variable to store the value of the current row's [pct] before calling CALCULATE:
Table =
VAR dat =
DATE ( 2016; 1; 1 )
VAR pct =
SUMMARIZE (
ADDCOLUMNS ( CALENDAR ( dat; dat + 99 ); "pct"; [Date] - dat + 1 );
[pct]
)
VAR pct_value_calculate =
ADDCOLUMNS (
pct;
"pct_value";
VAR CurrentPct = [pct]
RETURN
CALCULATE (
PERCENTILE.INC (
'Foreign exchange rates'[INDIRECT_FX_CCY_QUOTE];
CurrentPct / 100
);
'Foreign exchange rates'[FX_CCY] = "USD"
)
)
RETURN
pct_value_calculateI think a rough explanation is that when CALCULATE triggers a context transition (i.e. row context becomes filter context), any columns within the row context that were created with ADDCOLUMNS (like [pct]) are no longer accessible within the first argument of CALCULATE. This is because 'created columns' have no lineage so cannot be converted to filter context.
This means you can refer to [pct] outside CALCULATE or in one of CALCULATE's filter arguments, but not in CALCULATE's first argument. So the only way I can think of to access the value of [pct] is to save it in a variable before calling CALCULATE.
Owen :)
- chefe10 years ago
Helper II
Thank you Owen! That seems to work jusst fine :-)