I want to calculate difference between yesterday and day before yesterday.
I want to calculate the difference between yesterday and day before yesterday to see no. of files received in that day. my dates are in the below format in one column, i tried the datefiff function but couldn't get the desired results
please help
Best Answer
-
You could use a beast mode like the one below to sum the file collected if the date field is one or two days before today:
sum(case when DATE(`local_collect_date_time`) = CURRENT_DATE() - 1 then `FilesCollected` else 0 end) - sum(case when DATE(`local_collect_date_time`) = CURRENT_DATE() - 2 then `FilesCollected` else 0 end)
1
Answers
-
You could use a beast mode like the one below to sum the file collected if the date field is one or two days before today:
sum(case when DATE(`local_collect_date_time`) = CURRENT_DATE() - 1 then `FilesCollected` else 0 end) - sum(case when DATE(`local_collect_date_time`) = CURRENT_DATE() - 2 then `FilesCollected` else 0 end)
1 -
For Yesterday's value, you can try the following - (assuming you always want to compare against the current date and not the date from the column)
CASE
WHEN
YourDateColumn = DATE_SUB(CURDATE(),INTERVAL 1 DAY)
THENYourValue Column
END
Let me know if this does not work!'Happy to Help'0 -
@Dheeraj_1996 in your dataset what does each row represent? do you have a row per each file received and the
local_collect_date_time
is the timestamp of when the file was received?If what you want to know is how many more or less files you received yesterday than you did the day before yesterday, @MichelleH approach is a nice and clean solution for that, keep in mind that this one assumes you have a field
FilesCollected
that tells you how many entries you collected on the given timestamp, otherwise you can just change that part of the formula with a 1 and it'll work the same. The reason I'm asking is since you mentioned what you want is to see no. of files received in that day which could be to count entries with a timestamp that falls in the given date, which you can do by choosing only the first portion of the formula she suggested.Also keep in mind that all of these are based on the actual calendar day and not a 24 hours window, which if you have timestamps, it might be something else stakeholders might care about to have a more "realtime" metric.
0 -
My dataset loads every morning at 3AM, and it appends all the data in it by date.. I want to see how many files, records I have received in that particular day. lets say I have 3 files today in the dataset and 1 file yesterday. I have received 2 files today..
0 -
@Dheeraj_1996 then @MichelleH answer is what you're looking for. From the sample data you've provided, assuming you were running it on the 25th line 1 will return 12 and line 3 returns 5, so the difference would be 7.
If the idea is not to compare this to the current date, but be able to tell how many new files were received each day, then you'd need to use a window function instead, leveraging the LAG version (this will work since you've stated you have entries for every single day with no date gaps), it'd look something like:
COUNT(`local_collect_date_time`) - (LAG(COUNT(`local_collect_date_time`), 1) OVER( ORDER BY date(`local_collect_date_time`) ASC))
And you'd graph by
local_collect_date_time
grouping by day, with that you can get something that looks like:Keep in mind that since this is a lag function, the first date in your date range will have no previous day information available, so the delta will be the start date.
1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 731 Beast Mode
- 55 App Studio
- 40 Variables
- 683 Automate
- 175 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 122 Manage
- 119 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 107 Community Announcements
- 4.8K Archive