cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a calculated measure to a dropdown selector

mwickman
Explorer
0 Kudos
208

Hi

Can anyone tell me if it is possible to add a calculated measure to a list within a dropdown widget, in Analytics designer? If possible, can you provide the correct syntax.

Thank you!

Accepted Solutions (1)

Accepted Solutions (1)

N1kh1l
Active Contributor
0 Kudos

mwickman

Something like below, Assuming Table_1 is the table widget and Drodpwn_1 is the dropdown. You can place this code on initialization event or as per your need. This adds both calculated measure from model and story

var measure = Table_1.getDataSource().getMeasures();
console.log(measure);

for (var i=0;i<measure.length;i++)
	{
	Dropdown_1.addItem(measure[i].id,measure[i].description);
	}

Story

Hope this helps !!

Nikhil

mwickman
Explorer
0 Kudos

Thank you for the response Nikhil! I should have provided a little more detail. Your method is good for populating all measures, which would include any calculations. However, I have quite a few measures in my model and would like the dropdown list to include only a select few of them, including a calculation. Is it possible to reference a specific calculated measure? Thank you!

N1kh1l
Active Contributor
0 Kudos

mwickman

There can be 2 approaches which I can think of and they depend on how long is the list of measures intended to be added to dropdown. If they are handful, they can be just added manually to the Dropdown widget in the configuration. If the list is a bit long an array variable can be declared to store the list and then a check can be made before assigning them to the dropdown. Below is the adjusted code and I am adding a simple measure, a model level calculated measure and story calculated measure

Dropdown_1.removeAllItems();

var measure = Table_1.getDataSource().getMeasures();
console.log(measure);
var measure_list = ["Flow_Opening_LC","Flow_Total_LC","28757990-1719-4620-3507-315970181928"]; // Add all measure intended here

for (var i=0;i<measure.length;i++)
	{
		if(measure_list.indexOf(measure[i].id) !== -1 && measure[i].id)
			{
	Dropdown_1.addItem(measure[i].id,measure[i].description);
	}
	}

Hope this helps !!

Nikhil

Answers (0)