SELECT IFNULL({metric/venue_egm_h1_half_lga}, 0) +...
# gooddata-cloud
c
SELECT IFNULL({metric/venue_egm_h1_half_lga}, 0) + IFNULL({metric/venue_egm_h2_half_lga_2}, 0) you recommended this metric to solve the issue above. But I want to update to if both h1 and h2 are not null, then return h2 value
k
Based on the knowledge sources, you can use the
IF THEN ELSE
construct to achieve this logic. The condition "if both h1 and h2 are not null, return h2" translates to:
Copy code
SELECT IF 
  {metric/venue_egm_h1_half_lga} <> NULL AND {metric/venue_egm_h2_half_lga_2} <> NULL 
THEN 
  {metric/venue_egm_h2_half_lga_2} 
ELSE 
  IFNULL({metric/venue_egm_h1_half_lga}, 0) + IFNULL({metric/venue_egm_h2_half_lga_2}, 0) 
END
This works as follows: • If both metrics are non-null → returns the H2 value. • Otherwise (i.e., one or both are null) → falls back to the original
IFNULL
sum behaviour, treating nulls as
0
. A few things to keep in mind: • The
<> NULL
comparison in MAQL translates to
IS NOT NULL
in SQL, as noted in the relational operators documentation. [Relational Operators] •
IF THEN ELSE
is a simplified version of
CASE WHEN
, so the same multidimensionality rules apply — if you run into issues with slicing, you may need to wrap the expression in a
SUM
aggregation container. [IF THEN ELSE; CASE] If your intent for the "else" branch is simply to return
0
(rather than the sum), you can simplify accordingly:
Copy code
SELECT IF 
  {metric/venue_egm_h1_half_lga} <> NULL AND {metric/venue_egm_h2_half_lga_2} <> NULL 
THEN 
  {metric/venue_egm_h2_half_lga_2} 
ELSE 
  0 
END
Adjust the
ELSE
branch to match whatever fallback behaviour you need. 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups. 👀 Our Support team monitors all messages and will jump in if needed.
c
this issue is when I filter data to H1, it doesn't show in the view.
Resolved
j
Hi Cathy, I just want to confirm that you have resolved your issue with the metric. If you are still facing issues, could you please provide a link to the report you are working on? Also, for any follow ups to your inquiries, please keep the context in the same thread. Each new comment opening a new thread in a slack channel will trigger a new ticket for Support.
c
Thanks Joseph, the issue has been resolved. The formular in GD is quite tricky, ifnull give the correct result.