Is there any easy way to modify an existing arithm...
# gooddata-ui
j
Is there any easy way to modify an existing arithmeticMeasure for an insight? Say I have an AM thats expression is something like this
Copy code
sum(fact A) / sum (measure B)
is there anyway to modify it to be
Copy code
sum(fact A) / sum (measure D)
or would would the best way be for me to just create a new arithmeticMeasure with the values I want and plug that into my existing insight?
d
Hi Justin, we don’t provide such function to modify the operands of the arithmetic measure, you would probably be better off creating a new one. There are some functions that could help you get the data from the original measure: • measureArithmeticOperands()measureArithmeticOperator() • and others like measureFormat, measureAlias, etc. they should all be mentioned in the API Reference for the sdk-model package and they all have the naming pattern of measureABC
j
@Dan Homola once again thanks for the help. Though it looks like I am mistaken, the measure I am dealing with isnt an arithmeticalMeasure but a MAQL metric, is there a good way for me to figure out what measures/attributes have composed the metric from goodata.ui without having to look up its expression in the workspace catalog?
d
No problem 🙂 there is an endpoint in the SPI that returns the “tokenized” MAQL expression for a given measure. This will give you a list of tokens of the measure and the tokens related to measures, facts, attributes etc. will have their type set so you don’t have to parse the MAQL yourself. Here is a short example how to get all the fact ids from the metric:
Copy code
import { idRef } from "@gooddata/sdk-model";
import { IObjectExpressionToken } from "@gooddata/sdk-backend-spi";

const tokens = await backend
    .workspace(workspace)
    .measures()
    .getMeasureExpressionTokens(idRef("YOUR_METRIC_ID"));

const relatedFactIds = tokens
    .filter((token): token is IObjectExpressionToken => token.type === "fact")
    .map((token) => token.id);
similarly for othe object types, the full list is available in the source code. Just a note for the naming: “displayForm” there is what is called “label” in GoodData.CN. I hope this helps 🙂
j
Thanks this is good info. I was looking around the documentation and was wondering if there was a way for me to create a new metric in goodata.ui. I am already familiar with creating simple measures and arithmeticMeasures, but I am not seeing if there is a way for me to make a measure and specify a MAQL query to create it, is that possible?
d
Yes, that is possible, there are “sisters” to the
getMeasureExpressionTokens
method: •
createMeasure
updateMeasure
deleteMeasure
all of those “live” in the
backend.workspace(WORKSPACE).measure()
part of the SPI. Check the definitions on GitHub. You provide the MAQL string as teh
expression
property of the input objects. I hope this helps 🙂