Use Case 4: Convert Hours in the Day to Day Parts

This use case converts hours in the day into day parts; for example, morning or afternoon.

Raw Data Goal
Column named Hour of Day. Create the formula field “Day part” that assesses the hour of the day and determines if the value is Morning, Midday, Afternoon, Evening, or Overnight.
  1. For Field Label, enter Day part.
  2. For Formula Return type, select Text.
  3. In the syntax editor, enter the formula: IF(sourceField['Hour of Day'] >= 6 && sourceField['Hour of Day'] < 10, 'Morning', IF(sourceField['Hour of Day'] >= 10 && sourceField['Hour of Day'] < 15, 'Midday', IF(sourceField['Hour of Day'] >= 15 && sourceField['Hour of Day'] < 19, 'Evening', IF((sourceField['Hour of Day'] >= 19 && sourceField['Hour of Day'] < 24) || (sourceField['Hour of Day'] >= 0 && sourceField['Hour of Day'] < 6), 'Overnight', "Unclassified")))).
    If the raw data doesn’t have a separate column for Hour of Day, you can use the same formula by reading in a Date with Timestamp and parse out the timestamp.
  4. In the test input box, validate the formula using these combinations.
    • “Hour of Day” with the value of “6” returns “Morning”.
    • “Hour of Day” with the value of “12” returns “Midday”.
    • “Hour of Day” with the value of “18” returns “Evening”.
    • “Hour of Day” with the value of “19” returns “Overnight”.
    • “Hour of Day” with the value of “23” returns “Overnight”.
    • “Hour of Day” with the value of “0” returns “Overnight”.
    • “Hour of Day” with the value of “5” returns “Overnight”.
  5. Click Save.
  6. Verify that “Day part” is added as a new field.