Is there any way to cast a string as a number with...
# gooddata-cloud
c
Is there any way to cast a string as a number with MAQL? I have a number that is required to be a string within the data but i also need to compare it to a integer
k
Thinking completed The knowledge sources do not explicitly mention a
CAST
or type-conversion function in MAQL for converting a string to a number. However, depending on your use case, there are a couple of approaches worth considering: Option 1: Use a Computed Attribute with CASE/WHEN If you need to compare a string-stored number to integer thresholds and bucket the results, you can use a computed attribute with MAQL's
CASE/WHEN
logic directly against the string label:
Copy code
SELECT
  CASE
    WHEN {label/your_string_field} = "1" THEN "Category A"
    WHEN {label/your_string_field} = "2" THEN "Category B"
    ELSE "Other"
  END
This avoids needing a numeric cast by comparing string values directly. [Computed Attributes] Option 2: Use Relational Operators on the String Label MAQL supports
=
,
<>
,
IN
, and
NOT IN
comparisons on attribute labels. If your values are discrete, you can filter using string equality: [Relational Operators]
Copy code
SELECT {metric/my_metric} WHERE {label/your_string_field} IN ("100", "200", "300")
Option 3: Handle the Transformation Upstream The most robust approach — especially if you need true numeric comparisons (e.g.,
> 500
) — is to cast the column to a numeric type in your data warehouse/ETL layer and expose it as a fact in the Logical Data Model. MAQL operates on the LDM and does not perform type casting natively. In summary, MAQL does not appear to support an explicit
CAST
or type-coercion function. If string-to-integer comparison is critical, the upstream transformation approach is the most reliable path. 👍 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.
m
Hi Chris, we have reviewed our AI Assistants response and can confirm its feedback and the options provided. But please feel free to let us know if you have any further questions, or please feel free to write our AI Assistant directly if you need any further help.