Grouping Dates with consecutive weeks
Hi,
I have to visualize Projected Out of Stock Items and the date it goes out of stock in the inventory.
I have a table which shows when the item may go out of stock. This table shows the Projected Inventory for every Monday of the week.
Item | Location | Projected Inventory | Date |
A1 | L1 | 0 | Aug 20, 2018 |
A1 | L1 | 0 | August 27, 2018
|
A1 | L1 | 54 | Sep 03,20-18 |
A1 | L1 | 49 | Sep 10, 2018 |
A1 | L1 | 44 | Sep 17 |
A1 | L1 | 39 | Sep 24 |
A1 | L1 | 32 | Oct 1 |
A1 | L1 | 25 | Oct 8 |
A1 | L1 | 18 | Oct 15 |
A1 | L1 | 12 | Oct 22 |
A1 | L1 | 5 | Oct 29 |
A1 | L1 | 55 | Nov 5 |
A1 | L1 | 45 | Nov 12 |
An item is considered to be Out of Stock if the : Projected Invenotry<20. Since the data is for every Monday of the week, it may take few weeks for the item to come back on stock(ie PI > 20).
As can be seen in the table, Item A1 goes out of stock on Aug 20, 2018 and comes back on stock on Sep 03, 2018. The output table desired is :
Item | Location | PI | Date Out of Stock |
A1 | L1 | 0 | Aug 20, 2018 |
A1 | L1 | 18 | Oct 15, 2018 |
This is quite complex for me. Any help would be greatly appreciated.
Regards,
Prajwal
Best Answers
-
So what I would do is first take your table of 4 columns and add a new column called 'Prior Week Inventory'. This gives you a baseline to compare against.
In a SQL transform you could do something like this. (I'll call your current table datasetA)
SELECT a.*,
CASE WHEN
(SELECT b.`Projected Inventory` FROM datasetA AS b where DATE_SUB(a.`Date`, INTERVAL 7 DAY) = b.`Date`) IS NULL
THEN '20'
ELSE
(SELECT b.`Projected Inventory` FROM datasetA AS b where DATE_SUB(a.`Date`, INTERVAL 7 DAY) = b.`Date`)
END AS 'Prior Week Inventory'
FROM datasetA AS aWith your new dataset you can create a filter at the card level to remove the rows that don't apply.
That would look like this:
CASE WHEN `Prior Week Inventory` >= 20 AND `Projected Inventory` < 20 THEN 1 ELSE 0 END
Set your filter to = 1 and that should give you the card you're looking for.
Best of luck and let me know if you have any questions,
Valiant
0 -
If SQL is not your thing (like me) you can get the same new column using the lead function in magic ETL
0 -
In magic ETL the function isin the Rank & Window file. Check out the knowledge base about it.
0
Answers
-
So what I would do is first take your table of 4 columns and add a new column called 'Prior Week Inventory'. This gives you a baseline to compare against.
In a SQL transform you could do something like this. (I'll call your current table datasetA)
SELECT a.*,
CASE WHEN
(SELECT b.`Projected Inventory` FROM datasetA AS b where DATE_SUB(a.`Date`, INTERVAL 7 DAY) = b.`Date`) IS NULL
THEN '20'
ELSE
(SELECT b.`Projected Inventory` FROM datasetA AS b where DATE_SUB(a.`Date`, INTERVAL 7 DAY) = b.`Date`)
END AS 'Prior Week Inventory'
FROM datasetA AS aWith your new dataset you can create a filter at the card level to remove the rows that don't apply.
That would look like this:
CASE WHEN `Prior Week Inventory` >= 20 AND `Projected Inventory` < 20 THEN 1 ELSE 0 END
Set your filter to = 1 and that should give you the card you're looking for.
Best of luck and let me know if you have any questions,
Valiant
0 -
Hi,
I am getting the following error when I run the SQL transform:
"The database reported a syntax error. Subquery returns more than 1 row"
Regards,
Prajwal
0 -
If SQL is not your thing (like me) you can get the same new column using the lead function in magic ETL
0 -
Hi,
Which function should i use exactly?
I tried but could not figure it.
0 -
Can anyone help me out with this error?
I am not able to figure it out.
0 -
In magic ETL the function isin the Rank & Window file. Check out the knowledge base about it.
0 -
Thanks a lot. It worked like a charm.:)
0
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.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive