Custom metrics involving total of table

Hello All,

my question is so simple that I can’t understand why I can’t get it to work…

I have a variable time_to_event_group that is a string representing different group. I want to calculate the cumulative count of this divided by the total number of records in the table.

custom_metric = runningSum(count({time_to_event_group}), [{time_to_event_group} ASC]) / count({row_id})

This is actually a valid expression, but when I visualize this as a line (X=time_to_event_group, Y=custom_mertric), the count that is used in denominator is evaluated as the count inside a specific time_to_event_group instead of the entire table. Note that I’m just trying to get a constant number here count({row_id}).

Thanks for the help.

F.

Hello @Lyonnet_florian , welcome to the QuickSight community!

One thought I have to get around the order of evaluation is using PreAgg on your row id count. Please let me know if the following calculated field throws an error:

runningSum(count({time_to_event_group}), [{time_to_event_group} ASC])
/
countOver({row_id}, [ ], PRE_AGG)

Hi @duncan
Thanks a lot for the suggestion. I have tried different version around this but I’m always getting the error “Mismatched Aggregation: Custom aggregations can’t contain both aggregated and nonaggregated fields, in any combination”

F.

Hey @Lyonnet_florian !

Thank you for getting back to me with the error! This may be happening because the time_to_event_group field is a string. You might just need to wrap one part in a sumover to make it an aggregate. Could you try nesting the last part in sumOver?:

sumOver(count({row_id}, [ ], PRE_AGG)

Hey Duncan,

thanks for the feedback. Here is what I tried

F.

also tried that
and


but same result

Hello @Lyonnet_florian !

Can you post a screenshot of the visual that is not displaying correctly? I tried to recreate this issue so I could understand what is happening better but I think I’m missing something.