Conditional statement in metric don't work properly in Gooddata report

229 Views Asked by At

I have this metric:

metric_which_is_not_working.png

  • The first value right above the "if" statement should be considered just for dates after September 1st;
  • The second value right above the "else" statement should be considered just for old dates (before September 1st).

What happens is that when I put the "hour" attribute inside the report, the value above the "if" statement is considered even for old dates.

The left report uses the same metric but without the hour attribute:

same_metric_with_different_values.png

Why this happen? Can I do something to bring the right values?

OBS: I also tried to use the "case" statement in place of the "if" but I get the same result.

2

There are 2 best solutions below

3
On

You have to put the aggregation function (SUM in this case) around the CASE statement, not inside it. The reason is that you probably want to evaluate the condition on the fact table, not on the resulting aggregation function.

0
On

I solved this up by removing the "if" clausule (which don't seems to work with many filters in the report) and including the sum of 2 metrics containing in each of they the respective date filter:

New metric using WHERE rather than IF

This solved my problem for now, but I'm still looking for new ways to make this metric for performance reasons, so if anyone has a new guess, I'll be happy to test it.