Filtering Dates to Get the Last Access Date
Hello All,
I have created a card with the following fields (see Table 1) and trying to edit it using the Beast mode. I am basically looking for help to filter rows the courses last access by a user with the number of days (Today’s Date - DayAccessed). Below is a user “John Doe” who accessed two courses on three different days.
Table 1
FirstName | LastName | CourseName | DayAccessed |
John | Doe | Fall 2020 CIS 101 | 2020-11-21 00:00:0000 |
John | Doe | Fall 2020 CIS 101 | 2020-11-20 00:00:0000 |
John | Doe | Fall 2020 CIS 101 | 2020-11-19 00:00:0000 |
John | Doe | Fall 2020 BIO 222 | 2020-11-19 00:00:0000 |
John | Doe | Fall 2020 BIO 222 | 2020-11-17 00:00:0000 |
John | Doe | Fall 2020 BIO 222 | 2020-11-16 00:00:0000 |
Result will look like this table 2 (below) showing:
- Only the row that includes the last day the user accessed each course
- A new additional column (DaysAccessed) containing the number of days since last accessed
- Plus change the DayAccessed field from “2020-11-21 00:00:0000” to “2020-11-21”
Table 2
FirstName | LastName | CourseName | DayAccessed | DaysAccessed |
John | Doe | Fall 2020 CIS 101 | 2020-11-21 | 4 |
John | Doe | Fall 2020 BIO 222 | 2020-11-19 | 6 |
Thanks in advance.
Syed
Best Answer
-
Here's a screenshot of what it would look like in analyzer to backup my earlier post.
**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.2
Answers
-
Hey Syed,
RE: DateDiff Column -- Add a calculated field for DATEDIFF(CURRENT_DATE - `DayAccessed`) - it will give you the number of days between "today" and the value in the `DayAccessed` column. You can then add this calculated field to your table.
RE: Date Formatting -- I'd personally recommend handling this at the ETL level so you don't have to constantly carry it around in your BeastModes. You would do this via CAST/CONVERT/SET COLUMN TYPE depending on your ETL vehicle. I'm making this recommendation presuming your "timestamp" values are meaningless. If you must handle it at a BeastMode level, then you can use DATE or DATE_FORMAT to convert to your desired output.
1 -
You can show the most recent day accessed by clicking on the pencil icon for the Days Acccessed column in the column list and choose MAX. You can also format the date to just show the date in the same edit area by clicking on Format and choose Date Shorthand.
To get the difference between the first day accessed and the last day accessed by a person and class, create a beast mode that contains this formula:
DATEDIFF(MAX(`DayAccessed`),MIN(`DayAccessed`))
You can then drag this field into your column list and it should produce the results you are looking for.
**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 -
Hey @CCCDomo
Within an ETL you'd need to do a Group By tile to group based on the First, Last and Course names. Then for your resulting column select the Maximum aggregate. That will get you the last time it was accessed. You can then take that data output and pipe that into a Date Operations tile to calculate the number of days since last accessed. Just select "Difference Between Dates" for the operation and "Days" for your unit of measurement. Then choose "Value" and then select "current date" from the date selector for the first value and your "DayAccessed" for the second value. This will then get you the data you need.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Thanks for your super quick reply RACERX!
I am getting the following error when I try to add the filed using DATEDIFF(CURRENT_DATE - `DayAccessed`) although the Best mode validate without any problem.
"An issue has occurred during processing. We are unable to complete the request at this time."I do not think it is happening because field DayAccessed is kind of timestamp format compared to the output I get from the "CURRENT_DATE" which is slightly different because I also tested using the following with the same error:DATEDIFF(CURRENT_DATE - 1) and DATEDIFF(CURRENT_DATE - CURRENT_DATE)They both validate fine too.0 -
Here's a screenshot of what it would look like in analyzer to backup my earlier post.
**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.2 -
@MarkSnodgrass 's solution would work as well and likely be simpler. I have seen DATEDIFF not work correctly sometimes so I prefer the UNIX_TIMESTAMP method where it converts dates to a number in seconds and then doing some simple math:
ROUND(( UNIX_TIMESTAMP(CURRENT_DATE) - UNIX_TIMESTAMP(MAX(`DaysAccessed`)) / 60 * 60 * 24) - 0.5, 0)
Using -0.5 and the ROUND function it's truncating the number of days to be whole numbers that have passed.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Thanks MarkSnodgrass!
I go the first two working including the last date of access filtered and the date format changed.
To get the number of days last access I made minor changes to the code you provided as below and it is working too.
DATEDIFF(CURRENT_DATE(),MAX(`DayAccessed`))
1
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
- 101 SQL DataFlows
- 622 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 748 Beast Mode
- 59 App Studio
- 41 Variables
- 686 Automate
- 176 Apps
- 453 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 396 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 125 Manage
- 122 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 109 Community Announcements
- 4.8K Archive