Activation Time <10
I'm trying to get a percentage of less than 10 mints, in dataset I have values where start time is before the arrival time and instead of counting them as negative it displaying positive, how Can I fix this.
SUM((CASE
WHEN (TIME_TO_SEC(timeDIFF(`Start Time (UTC)`, `Arrival Time (UTC)`)) / 60) <=10 THEN 1
END))
/
SUM((CASE WHEN `Case Number` is not null then 1
end))
Best Answers
-
Ah the reason I'm not a fan of TIMEDIFF. In cases like this I prefer to use UNIX_TIMESTAMP and math to calculate the difference in seconds between two different timestamps.
SUM((CASE WHEN ((UNIX_TIMESTAMP(`Start Time (UTC)`) - UNIX_TIMESTAMP(`Arrival Time (UTC)`)) / 60) <=10 THEN 1 END)) / SUM((CASE WHEN `Case Number` is not null then 1 end))
One question of clarification - If a start time comes 15 minutes before the arrival time (-15 minutes) should that be included since -15 < 10 or should it be excluded since the absolute duration is greater than 10? If it should be excluded you can wrap the subtraction in the ABS function to get the absolute value.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
You can use the ABS() function to turn any negative number into a positive number.
ABS
Returns the absolute value for all values in a numeric column.In other words, any negative values become positive, and positive values stay the same. This is valuable when you want to see aggregation without considering positive and negative values.
ABS('Operating Budget')
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1
Answers
-
You can utilize an additional clause inside your case statement to swap the values if necessary:
SUM((CASE WHEN `Start Time (UTC)` <= `Arrival Time (UTC)` AND (TIME_TO_SEC(timeDIFF(`Start Time (UTC)`, `Arrival Time (UTC)`)) / 60) <=10 THEN 1 WHEN `Start Time (UTC)` > `Arrival Time (UTC)` AND (TIME_TO_SEC(timeDIFF(`Arrival Time (UTC)`, `Start Time (UTC)`)) / 60) <=10 THEN 1 END)) / SUM((CASE WHEN `Case Number` is not null then 1 end))
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Thanks, but this is giving me no results also I need to include those rows.
0 -
Try adding ELSE 0 in your case statement like this:
SUM((CASE WHEN (TIME_TO_SEC(timeDIFF(`Start Time (UTC)`, `Arrival Time (UTC)`)) / 60) <=10 THEN 1 ELSE 0 END)) / SUM((CASE WHEN `Case Number` is not null then 1 ELSE 0 end))
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
It will still not solve the problem as the Response time should be negative and not positive. like the first one -8 mints
0 -
Interestingly, when I put this into my beast mode:
TIMEDIFF('4:46:11 PM','4:54:28 PM')
It resulted in a value of 23:51:43 rather than the negative approx. 8 minutes as you would expect. It seems as though Domo's implementation doesn't match MySQL's implementation, which is what it typically follows.
I think if you took this knowledge and added your time to sec function and then subtracted from 86400 (seconds in a day) and divide by 60, you will get to your minutes and be able to put this into your case statement.
I would suggest building this up gradually after adding each function and view the results in the table card to make sure you are seeing the results you would expect rather than trying to jump to the final result.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
Ah the reason I'm not a fan of TIMEDIFF. In cases like this I prefer to use UNIX_TIMESTAMP and math to calculate the difference in seconds between two different timestamps.
SUM((CASE WHEN ((UNIX_TIMESTAMP(`Start Time (UTC)`) - UNIX_TIMESTAMP(`Arrival Time (UTC)`)) / 60) <=10 THEN 1 END)) / SUM((CASE WHEN `Case Number` is not null then 1 end))
One question of clarification - If a start time comes 15 minutes before the arrival time (-15 minutes) should that be included since -15 < 10 or should it be excluded since the absolute duration is greater than 10? If it should be excluded you can wrap the subtraction in the ABS function to get the absolute value.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
Thank you Grant, this has solved the problem but not sure why it's counting the time more than 10 mints :(
it's only few rows and doesn't effect the # that much but still...
0 -
is there a way to make the negative numbers into positive?
As this solve the problem with time but then when you sum it's not the right number.
0 -
You can use the ABS() function to turn any negative number into a positive number.
ABS
Returns the absolute value for all values in a numeric column.In other words, any negative values become positive, and positive values stay the same. This is valuable when you want to see aggregation without considering positive and negative values.
ABS('Operating Budget')
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
thank you, Grant & Mark.
This really solve the problem :)
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive