Hey All, need help with a metric. I'm trying to c...
# gooddata-cloud
s
Hey All, need help with a metric. I'm trying to calculate the average number of days between 2 dates. However when I run my metric I get the error: "reason": "Enumerating datetime attributes='[attribute/DUE_DATE.day/ldm_authoring]' is not allowed"
Copy code
"traceId": "cb646bb151a6479a4bc64d36951a3be2"
m
Hi Steve, from my experience this error usually happens when you try to output only the date dimension and nothing else or the date dimension in the insight is not considered related to the metric you are using. Could you maybe share more details i.e. how does the metric look like and how are the dates related in your data model? BTW are you using the DATETIME_DIFF function to calculate the number of days?
s
I've tried it a couple of ways: What I'm trying to do is to add a metric that calculates a date difference.
I have a date called due date.
i want a metric that is the number of days bettween today and that value
First attempt was a metric like: SELECT SUM(DATETIME_DIFF(<metric>.day,THIS(Day))
then tried a straight metric of the datetime_diff
and then load that one in,....
but same result
m
Oh I see, so it is “dynamic” date for THIS(Day). I believe it might be very similar case as described here. The trick is to add
BY {dataset}
to the metric where you are calculating the date diff
SELECT AVG(
(SELECT
DATETIME_DIFF( {DateOfBirth - Year{label/DateOfBirth.year}, THIS(YEAR) )
BY {dataset/your_dataset}
)
)
I agree that this is not very intuitive and this case was already reported to GoodData product team to improve how it works or improve the documentation.
s
yeah thats not obvious at all.
It seems to work. Not sure how we would have known that based on the documentation.