Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Returning numeric values from a dropdown list


This might be a rudimentary question (as mine seem to be!) but I have created a select question with a drop-down list of prices (I've created my own take on the VWPSM but only to the extent I want to use the median value derived from the four measures as the base price in an ACBC).

The dropdown has 107 prices ranging from 350,000 - 3million in 25,000 increments. I want to return the numerical value seen by the respondent not it's position in the list. Is there a piece of code I can use that will achieve this?

Preferably one that doesn't require me to code out  107 SETVALUE statements... can anyone help with a slick bit of code?

Many thanks
asked Jun 27, 2017 by Jasha Bowe Bronze (1,745 points)
retagged Jun 27, 2017 by Walter Williams

1 Answer

+1 vote
Best answer
If you want to use it for display purposes or store the median value, here's some tips ...

Let's assume Q1 is the question used to ask the price in the drop-down list.

If you create a list called MedianPriceList with all 107 median prices included (not the ranges), you can display the selected price from Q1 as such ...

Display on a page: [%ListLabel(MedianPriceList,Q1)%]
Save to a value called MedianPrice:

You would need to define MedianPrice as a Pass-In Field variable of type Whole Number.

Does that help?
answered Jun 27, 2017 by Paul Moon Platinum (67,780 points)
selected Jun 27, 2017 by Jasha Bowe
Hi Paul,

I thought you might be able to help me. I think it might be even simpler than that. I don't really want to show them the price again, I just want to use the numeric value that is associated with the selection. So that if I call on [% Q1%] that the numeric value that is Q1 is the actual price the respondent selected not its place in the master list. Essentially I want to return [%Label(Q1)%] BUT i want the returned value to be recognized as numeric so I can perform mathematical functions with it... Does that make sense?
I understand that [%Label(Q1)%] will give you a range like "$350,000 - $375,000". You would rather save something like $362,500. Is that correct?

I would create a new list that contains all 107 mid-range values.

and so on ...

You can use ONE instruction to save the median value in a defined variable called MedianPrice ...


MedianPrice will be saved to the database as a variable which you can export. You can also use [%MedianPrice%] to display it anywhere.

Does that make sense?
Sorry Paul as usual I have made a meal of this. I don't have ranges. each member of the list is just 1 number. So
1 - 350,000
2 - 375,000
And so on to
107 - 3,000,000

And I just want to return the value 3,000,000 not 107. That's all. Your method is far more clever than I require (though I'll definitely use it later.

So is all I need to do something like  [%SetValue(ListLabel(Q1))%] ?
Jasha, you are almost on the right track mate.

You only need to extract the label from the Q1 response based on the list you just mentioned.

Use this to save the Q1 label to a variable called MedianPrice ...

Use this to display the Q1 label on any survey page ...

Give them both a try.
Hi Paul,

Last time I promise!

I have created the pass-in fields and I'm now trying to execute the script and I get the error that  'The function call 'SetValue' contains an invalid number of arguments or an argument with an incorrect type.'

With this as the piece of script


Where WPSM1Price is the pass-in and the Dropdown list question is VWPSM1

Any thoughts?
Try this ...


I believe Sawtooth Software needs to convert the label to a number given the pass-in field is expecting a whole number.
BINGO!! You are a legend.

Thanks Paul
Nice one! You'll be a legend at this in the not too distant future.

And keep the questions coming ...