Extract the last value from a Range Variable Value

var variable = chart_1.getDataSource().getVariables()[0];
var value = chart_1.getDataSource().getVariableValues(variable)[0];
var rangeValue = cast(Type.RangeVariableValue, value).to;
var filter_value=rangeValue.slice(4,7);

// apply the filter
chart_2.getDataSource().setDimensionFilter("DIMENSION",filter_value);
Code language: JavaScript (javascript)
StepWhat it doesWhy it matters
getVariables()Finds available prompts (variables) on the chart’s data sourceSo you know which variable you’re working with
getVariableValues()Gets the current value(s) set for that variableTo read what the user or story has selected
cast(Type.RangeVariableValue, value)Converts the value into a structured object with .from and .toSo you can access the start/end of a date or period range
.toGets the end of the selected range (e.g. 2025008)You probably care about the latest period selected
slice(4,7)Extracts the month part of a string like “2025008”To isolate the MM (month) part from YYYYMM format
Scroll to Top