hi, is there a way to create a case when statement...
# gooddata-platform
a
hi, is there a way to create a case when statement not using metric? I'd like to create a categorical variable using the logic statement but it seems the options are limited to only numerical formats and not text
m
That is correct, any business logic in GoodData can be only written in MAQL within a metric. And result of a metric can only be numeric. There is one way how to overcome this in the hosted GoodData Platform and that would be to use Computed Attributes feature. With this, you can use a metric to calculate some numeric value and then create a computed attribute which is based on this metric (and one other attribute by which the value of the metric is calculated). You can define fixed ranges and name them. You can then use this computed attribute as if it was a normal one. Please note that computed attributes are still considered beta and have some limitations, especially: • once created it can not be modified (only deleted) • if you ever need to migrate a computed attribute into another workspace (without using LCM bricks), it is a bit more complicated - see the steps here • there might be some issues with parent filters for computed attributes This feature is currently not available in GoodData.CN
a
i see ok, thanks. I was trying to create a histogram before, and ran into similar issues. Heard about Computed Attributes, but never attempted it. probably a good time to look into it then. Would you know when beta would become full release?
m
Also please note that the behavior of CASE/WHEN and IF statements in GoodData are slightly different than in SQL. In SQL those are always row-level operations which are applied on the level of raw data. In MAQL it can be evaluated on different aggregation levels, based on the context where the metric is used. And also MAQL works with it in a single-pass so it technically executes both/all branches of the condition and then performs an inner join between them on the appropriate aggregation level. This practically means that you might need to use IFNULL in your metrics in CASE/IF branches, if it could end up not being defined on the aggregation level where it is applied. (similar to doing
SELECT metric1 + metric2
vs
SELECT IFNULL(metric1,0) + IFNULLmetric2,0)
)
a
ah interesting! ok thanks for the clarification
m
It seems it has been in beta phase for several years now and I am not aware of any plans to change it currently. I know several enterprise customers are using this feature and I am not aware of any significant issues so if you are aware of the limitations and are OK with them, I think it is safe to use it.