Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

Calculated fields using string

Carlos Perez Ruiz asked on June 12, 2020

I have a question.
I want to create calculated fields using two or more fields. If this fields are numbers (are measurable), the component provide a way to create it, but if this fields are string i not found the way to do it.
By example:
I have 2 fields: ARTICLE_CODE (data type: string) and ARTICLE_NAME (data type: string), and I want to create a field like this : ARTICLE_CODE – ARTICLE_NAME, where the new field would be the concatenation of the previous two fields and a custom separator.
This is posible? (I use the v.2.8.2 of the component)
Thanks for the help.

3 answers

Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 15, 2020

Thank you for reaching out to us.
We want to kindly explain that Flexmonster does not provide the possibility to operate with strings in calculated values.
Our recommendation is to preprocess the data set in the way it contains the required field by default.
You are welcome to contact us in case additional questions arise.

Carlos Perez Ruiz June 16, 2020

Hi Illia,
Thanks for your answer. 
I have one more question about this.
This limitation of the component is considered as a future improvement of the component for next versions or it is not yet in the list of functionalities to develop?
Thanks for the information.

Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 18, 2020

Thank you for your feedback.
We would like to explain that such limitation is exposed due to the fact that all measures placed on the grid are aggregated (if pivot form is chosen). It means both fields from your example (ARTICLE_CODE and ARTICLE_NAME) will be aggregated as well. The output of any aggregation available for the string data type is numeric. As a result, calculated values are operating with numeric data rather than strings.
Our team wants to ask you to provide some additional details about your use case so we could find the best workaround.
First, it would be useful to know whether the pivot form (compact, classic) or the flat form is going to be used.
If the pivot form is used, please let us know whether the created field needs to represent the hierarchy with members or the measure.
As for now, we assume the initial requirement is to merge two existing fields (“ARTICLE_CODE” and “ARTICLE_NAME”) and display resulting members.
It is achievable through specifying one of the fields (“ARTICLE_CODE” or “ARTICLE_NAME”) as a property of another and complement the member’s caption with its property using the customizeCell hook.
Please see an example we have prepared demonstrating the described approach.
The following code snippet from the example demonstrates how the property type can be applied to the “ARTICLE_NAME” field:

mapping: {
type: "string",
caption: "Atrticle"
type: "property",
hierarchy: "ARTICLE_CODE"

The code block below is responsible for modifying the text of headers representing the article code. It complements the content of the cell with its property – article name.

flexmonster.customizeCell((cell, data) => {
if(data.hierarchy && data.hierarchy.uniqueName == "ARTICLE_CODE" && data.type == "header")
cell.text += ` - ${['ARTICLE_NAME']}`

Detailed information about properties and API calls used in the example is available in our documentation:

Please let us know if it works for you.
If your use case differs from the described one, we want to ask you to provide us with a detailed description of the result you want to achieve.

Please login or Register to Submit Answer