Hey there, we are looking to dynamically choose a ...
# ask-questions
Hey there, we are looking to dynamically choose a column in the table used to define our metrics based on the value in another table. We could hard code which column to choose based on the value like in the example below, but I’m wondering if there is a way to do this where we don’t have to specify
explicitly, e.g. whatever the value is for
it will be used as the column name to select in
. Has anyone encountered this type of dynamic column selection? (cc @ambitious-apartment-58735 @orange-magician-36994)
Copy code
case when test_meta_data.test_user_id = 'user_id_1' then USER_ID_1 
else USER_ID_2 end as USER_ID,
pageview as value
from test_clickstream
(select test_user_id
from test_meta_data
where experiment_id = '{{ experimentId }}') test_meta_data
Hi Juliana, thanks for reaching out! It's likely you won't hear from us until we're back within business hours tomorrow. We'll follow up soon
Hmmm, I don't think so. I'm sure there's some way to do this in SQL but I doubt it can be used in the context of a CTE (which is how we inject your metric definition code into the final analysis SQL). Would definitely be curious if you found a way to do this that didn't rely on multiple statements.
Got it, that’s more or less what we concluded too. I’ll follow up if we find another solution!
👍🏻 1
thankyou 1