Get Free Trial

Custom field for measures

Answered
Artsem asked on June 28, 2021

Good day,
Can I set my field in Measures by type: [{uniqueName: ‘test’, myField: ‘myField’}]. Or the second option, use field format but don’t use setFormat

3 answers

Public
Vera Didenko Vera Didenko Flexmonster June 29, 2021

Hello,
 
Thank you for writing to us.
 
Could you please provide a bit more details on what you are trying to achieve?
More insight will help us to provide the most suitable solution for your case.
 
Looking forward to your reply
 
Kind regards,
Vera

Public
Artsem June 29, 2021

Hello,
When I call flexmonster.getMeasures (), I would like to get an array with metrics, in which I have a custom field. Can I do this? Or the second option in the format field could be to set my own format without using setFormat. By this field, I would like to determine which method I need to apply for additional formatting

Public
Vera Didenko Vera Didenko Flexmonster June 29, 2021

Hello, 
 
Thank you for providing additional details.
 
If we understand correctly, you would like to assign a specific value to your measures. Depending on that value, you would like to apply specific formatting rules to the measure.
 
If so, it seems the format measure property would work for your case. With this property, you can assign a format name as a string value:

slice: {
rows: [{...}],
measures: [
{
uniqueName: "Price",
format: "currency"
},
{
uniqueName: "Quantity",
format: "amount"
}
]
},
formats: [
{
name: "currency",
currencySymbol: "$"
},
{
name: "amount",
currencySymbol: " pcs.",
positiveCurrencyFormat: "1$"
}
]

This way, you can assign specific formatting rules to each measure. Also, the format property value of each measure is returned by the getMeasures() API call.
Here is a JSFiddle example for illustration: https://jsfiddle.net/flexmonster/h4aeLtsu/.
 
Would such an approach work for your case?
Looking forward to your reply.
 
Kind regards,
Vera

Please login or Register to Submit Answer