cancel
Showing results for 
Search instead for 
Did you mean: 

How to add script variable array to Table SAP Analytic application

Dhiraj_G
Explorer
0 Kudos

Problem Statement:- Trigonometric functions are not available in "Calculated measures"

So I read a measure from table using Table.getDataSource().getResultSet() and calculated the new array with trigonometric functions like "Math.cos(array_1).

This calculated array is stored in new script variable.

Now How can I add this Script variable (type= Array) to the table?

Or How can I convert this Script variable (type= Array) to new Measure?

Accepted Solutions (1)

Accepted Solutions (1)

N1kh1l
Active Contributor
0 Kudos

dhiraj_gadhave

Any script variable of type integer/number is available for use as calculation input control in Calculated measure but I do not think you would be able to use an array of type integer.

If you use any variable of type other than number/integer you will get below warning.

Now i am able to assign a value of 5 to this script variable and measure show up accordingly

If I make the variable as array of type integer I do not get error but nothing shows up in calculated measure (it makes sense).

Now if your model is a planning model you can use the API setUserInput(selectedData: Selection, value: string): to set the values in table.

So calculate your trigonometric values and then pass them to setUserInput api.

https://help.sap.com/doc/958d4c11261f42e992e8d01a4c0dde25/release/en-US/index.html#Planning_MsetUser...

Hope this helps !!

Please upvote/accept if this helps.

Nikhil

Answers (1)

Answers (1)

Dhiraj_G
Explorer
0 Kudos

nikhil_1486 Thanks for the reply, This is a very good example for using script variable in the calculated measures, I will use it .

The Original Problem reformatted as below:

I have a column B in the table with some numbers and I want to use column C as cos(column B), as Trigonometric functions are not available in calculated measures(Analytics Application) I am reading column B using onInitialization script

var arr = Table_5.getDataSource().getResultSet({"@MeasureDimension": "*******);

and then calculating the Cos function using below script

var value = ArrayUtils.create(Type.number);

var Cos = ArrayUtils.create(Type.number);

for (var k=0; k<arr.length;k++)

var string = arr[i][Alias.MeasureDimension].formattedValue;

var number = ConvertUtils.stringToNumber(string);

Cos[k] = Math.cos(number);

}

And now I want to add this variable Cos ( type:Array) to the column C in the original Table., or How can I use this variable Cos as measure for other charts ?