Cathy Liu
08/06/2026, 3:47 AMkapa.ai
08/06/2026, 3:47 AMIF THEN ELSE construct to achieve this logic. The condition "if both h1 and h2 are not null, return h2" translates to:
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:
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.Cathy Liu
08/06/2026, 3:53 AMCathy Liu
08/06/2026, 4:46 AMJoseph Heun
08/06/2026, 6:45 AMCathy Liu
08/06/2026, 11:08 PM