Grouping by the Hour and alerting based on count of usage per hour.



I am trying to do a group by using hour of day.  The date operator in Magic does not have that funcationality but curious how I can do it within magic or in SQL.  Here is my data where I want to count how many times a code was use in an hour for each day I want to use.

COUPON-CODEupdated_atOrder #Goal(Count of Usage by Hour)
10%17-Apr-20 10:04:5312
10%17-Apr-20 10:43:4922
10%17-Apr-20 5:43:2531
10%17-Apr-20 0:46:5341
10%17-Apr-20 17:10:1451
20%17-Apr-20 2:51:3861
20%17-Apr-20 6:42:5971
20%17-Apr-20 13:24:4982
20%17-Apr-20 13:53:1492
50%17-Apr-20 15:51:46101
50%17-Apr-20 16:02:26113
50%17-Apr-20 16:27:03123
50%17-Apr-20 16:27:03133

Best Answer

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤
    Accepted Answer

    In Magic:  create a copy of the column converted to TEXT and do a REGEX / STRING transform.

    In MySQL: use date_part functions (like hour).


    Best Solution:  split date and time (HH:mm) into separate columns during data ingestion.  THEN use a Fusion to join a Time Dimension table (where you have one row for every minute of the day).


    Why is Fusion the best model?  

    Because it minimizes the number of times you have to read and write the data. AND by using a Time dimension you can create custom groupings like ("Morning", "coffee-break", "evening") without using a complex beast mode in each of your cards.


    Why does splitting date_time make sense?

    Because you'll want to see a trend in behavior on Saturdays versus trend in behavior on Mondays.  By using a Time dimension you can avoid ugly beast modes.