Subtracting Dates Based on Other columns
I currently have a data set that looks something like this:
I want do compute a Date Diff for orders from the same account between orders 1 and 2.
So-- find accounts that have the same number in column A
Determine which two orders (rows) to pick, based on column B
Subtract the corresponding dates in column C
Example: Find Account A123-- subtract it's first order date from its second: 03/04/2021- 01/01/2021 and tell me how many days have passed.
How can I do this? Even better-- how can I do this in an ETL or BeastMode?
Thanks!
Answers
-
Hi @user027926, you'll need a combination of window and date diff functions in order to calculate the difference between the two dates. You will need to ask your Customer Success Manager to "enable window functions in beast modes" in order to make use of this.
A bit of food for thought also, doing something like (CASE when 'Order' = 2 then 'Date Ordered' END) - (CASE when 'Order' = 1 then 'Date Ordered' END) won't work as beast modes are calculated on a row basis. With this beast, either there will be values from Order 1 or 2 but won't have both captured. As a result, you'll have a value and NULL per row and also subtracting null from anything will give null, resulting in a blank output.
9 -
I find it is easiest to do this in Magic ETL utilizing the Rank & Window tile. Choose the Lag function and then choose order date asc and partition by your account number and order number. This will put the previous order date (when there is one) next to the next order. You can then use the formula tile and the datediff function to find the difference between the two dates. Here's a link to the KB article for Rank & Window.
https://domohelp.domo.com/hc/en-us/articles/360044876094-New-Magic-ETL-Tiles-Aggregate#3.
**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.3 -
Here's a Beast Mode that is doing what @amehdad is describing:
DATEDIFF(LEAD(MIN(`Date Ordered`)) OVER (PARTITION BY `Account Number` ORDER BY `Which Order Number is this`), `Date Ordered`)
This will calculate the difference between each order based on each customer.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2
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