I’m pretty sure you could put something together that would achieve something close!
There are two steps to my idea:
Get the timeframe filter value and reference it in LookML
Make a custom measure with different behavior based on filter value
Step 1: Get the filter value
The easiest way to get this would be the _filters[‘view_name.field_name’] Liquid variable. But, according to the Liquid reference, we can’t call this in sql parameters of a LookML field, so this may not be robust enough for our needs. Can you change the timeframe to a parameter instead? Then we can call it using the parameter parameter_name liquid variable.
Step 2: Create a conditional measure
Next, we’ll write a measure in LookML that listens to this parameter and returns the appropriate value.
measure: dynamic_measure {
type: number
sql: CASE WHEN (% parameter timeframe %) = 'ytd'
THEN ${metric_a} + ${metric_b}
WHEN (other condition...)
THEN (other result...)
END;;
}