Hi team! I am trying to return a date value as a ...
# gooddata-cloud
s
Hi team! I am trying to return a date value as a result of an aggregation in Good Data and hitting a wall. Use Case: Given a set of events that share the same start date, I want to compute the average end date across those events. My approach: Step 1: For each row, compute the number of days between the start date and the end date. Step 2: Take the average of those day counts. Step 3: Add the result back to the start date to get the average end date as a date value. Challenge: The challenge is that MAQL metrics can only return numeric values, so _DATETIME_ADD_ and MAX/MIN on dates are both blocked at the metric level. My Questions: • Is there a supported way to return a date from a MAQL metric? • If not, is this achievable via a computed attribute, custom metric, or any other GoodData construct? • Would the recommended approach be to handle the transformation upstream in the data source and expose it as a date dimension?
k
Hi! Great question — you've correctly identified the core limitation. Let me address each of your questions directly. Can MAQL return a date value? No. MAQL metrics always return numeric values — this is a fundamental constraint of the platform.
MAX(date)
or
MIN(date)
on their own return a numeric internal representation (e.g.,
2022
instead of a readable date), and there is currently no supported date formatting for metric outputs. [Community Slack] Your 3-step approach in MAQL Steps 1 and 2 are achievable in MAQL using
DATETIME_DIFF
and `AVG`:
Copy code
SELECT AVG(
  SELECT DATETIME_DIFF({label/start_date.day}, {label/end_date.day}, DAY)
  BY {dataset/your_dataset}
)
This gives you the average number of days between start and end dates as a number. [DATETIME_DIFF docs] Step 3 (adding the result back to get a date) is where MAQL hits its wall. While
DATETIME_ADD
exists, it is used in
WHERE
clauses for filtering — not to produce a date as a metric output value. The result of any metric expression will still be a number, not a displayable date. [DATETIME_ADD docs] Recommended alternatives 1. Handle it upstream in your data source (recommended): Compute the average end date as a proper date column in your ETL/SQL layer, then expose it as a date dimension or attribute in GoodData's logical data model. This is the most reliable approach and avoids the MAQL limitation entirely. [Community Slack] 2. Display the numeric result with formatting: You can display the average day-count metric and use metric formatting to make it more readable, but you cannot render it as a
mm/dd/yyyy
date string — that formatting is not currently supported for metrics. [Community Slack] 3. Dashboard plugin (advanced): If you're embedding dashboards, a plugin can perform more complex date logic dynamically and display the result in a text/KPI widget. [Community Slack] Summary The knowledge sources do not mention a "computed attribute" construct that would solve this within GoodData itself, so the upstream data source transformation is the most robust path for your use case. 👍 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., with interactive elements