Hi Team, I want to create a view like this. I've c...
# gooddata-cloud
c
Hi Team, I want to create a view like this. I've created metrics as SELECT SUM({fact/VENUE_EGMS}) WHERE {label/HALF} = "H1" , SELECT SUM({fact/VENUE_EGMS}) WHERE {label/HALF} = "H2" and SELECT CASE WHEN {label/HALF} = "H1" THEN {metric/venue_egm_h1_half_lga} ELSE {metric/venue_egm_h2_half_lga_2} END. But the view doesn't show in GD. The link is: 63. Annual Venue Report - GoodData Cloud
k
Looking at your setup, the issue is with your
CASE WHEN
metric. There are a couple of problems to address: Why the CASE Metric Isn't Working 1. CASE doesn't work at the base data level Your metric:
Copy code
SELECT CASE WHEN {label/HALF} = "H1" THEN {metric/venue_egm_h1_half_lga}
  ELSE {metric/venue_egm_h2_half_lga_2}
END
CASE evaluates on the aggregation dimension, not at the row level. When the CASE condition attribute (
HALF
) is not directly related to the visualization's slicing dimension, the metric cannot be computed. [CASE statement] 2. CASE with metric references in THEN/ELSE branches The recommended pattern is to wrap CASE inside a
SUM
aggregation container, and use facts rather than referencing other metrics directly in the branches. [CASE statement] Recommended Fix Instead of the CASE approach, since you already have your two filtered metrics (
venue_egm_h1_half_lga
and
venue_egm_h2_half_lga_2
), the simplest and most robust solution is to sum them directly using
IFNULL
to handle cases where one half has no data:
Copy code
SELECT IFNULL({metric/venue_egm_h1_half_lga}, 0) + IFNULL({metric/venue_egm_h2_half_lga_2}, 0)
This avoids the CASE limitation entirely. Without
IFNULL
, if one metric returns
NULL
(e.g., no H1 data for a venue), the entire sum returns
NULL
. [IFNULL fix] If You Must Use CASE Wrap it inside
SUM
and use facts directly:
Copy code
SELECT SUM(
  SELECT CASE
    WHEN {label/HALF} = "H1" THEN {fact/VENUE_EGMS}
    ELSE {fact/VENUE_EGMS}
  END
)
However, note that if you're slicing by an attribute unrelated to
HALF
in your visualization, you'll still get a "wrong case conditions" error. In that case, the
IFNULL
+ addition approach above is the better path. [CASE dimensionality] Also, since the GoodData support team has admin access to your workspace, they may be able to look directly at the metric and dashboard to help diagnose further. 👍 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 is not right, when both H1 and H2 have values, I want it show as H2