cancel
Showing results for 
Search instead for 
Did you mean: 

Need option to convert numeric to text

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

MustafaBensan
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

MustafaBensan
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

MustafaBensan
Active Contributor
0 Kudos

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-itera...

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.

TammyPowlas
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Tammy,

we are using the below version

DS version 1.6 SP3

Data Source: Bex query