Skip to Content
0

Need option to convert numeric to text

May 22, 2017 at 02:29 PM

74

avatar image
Former Member

I want to know if there is any option to convert numeric in design studio chart to text using if else condition.

for example if posting period =1, the it should display Jan

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Tammy Powlas
May 22, 2017 at 04:14 PM
0

Hi - are you using Design Studio (not "ByDesign Studio")?

Have you searched? When I search, I find these:

https://archive.sap.com/discussions/thread/3958010

https://blogs.sap.com/2014/07/10/design-studio-13-scripting-example-to-convert-number-to-date/

If these do not help, please share version, support pack, and data source.

Tammy

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Tammy,

we are using the below version

DS version 1.6 SP3

Data Source: Bex query

0
Mustafa Bensan May 23, 2017 at 01:48 AM
0

Hi Bhargav,

It sounds like you want to convert a numeric key value to a corresponding text description. This is best achieved via an array lookup as per the example I have given in the first discussion link Tammy has referenced.

Here is a code sample to illustrate the technique specific to your case of converting period numbers to month descriptions:

var period = 1;
var monthArray = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var monthText = monthArray[period - 1];  // Lookup text of month based on array index

APPLICATION.alert(monthText);

Regards,

Mustafa.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Mustafa,

I Need to display the posting period Numeric as text like Jan, Feb, Mar instead of 1,2,3.

I have used the code in the On select Event of the chart, but it is not displaying the text, instead an alert pop up is displayed as Jan.

period.png (5.9 kB)
0

Hi Bhargav,

The reason for the behaviour you have observed with the alert pop up is that you have literally copied the code I supplied, intended as guidance, without adapting it for your specific scenario.

Please answer the following questions to clarify your requirement:

1) What type of data source is assigned to your chart: BW BEx Query, HANA View or Universe?

2) If I understand your requirement correctly, you want to show the text "Jan", "Feb", "Mar" as the labels in the chart x-axis instead of "1", "2", "3"? If that is the case, then these texts should be available from the data source assigned to the chart. The approach will depend on your answer to Question 1 above about which type of data source you are using.

Regards,

Mustafa.

0
Former Member

Hi Mustafa,

1) Datasource is a Bex Query.

2) Your understanding is correct for point 2. But we are not able to maintain text in BW for that field, so we are looking for a workaround.

Thanks,

Bhargav

0

Hi Bhargav,

I am surprised to learn that you cannot maintain the text of the Posting Period in BW. Can you clarify why this is the case? For your scenario, the recommended approach is definitely to maintain the text in BW.

The only workaround would be to use the combination of the Community SDK Data Iterator and Bring Your Own Data Source components, similar to the techniques described in the following blog:

https://blogs.sap.com/2016/03/10/design-studio-16-data-blending-and-what-if-analysis-with-data-iterator-bring-your-own-data-source/

Basically, you would need to use the Data Iterator to loop through the data result set and substitute the Period Name for the Period Number and then create a new data source with the BYOD component which would then be assigned to your chart. However, I advise against this approach because you will need to replicate this for every application that uses the same BEx Query. You should definitely maintain the texts in BW.

Regards,

Mustafa.

0