Need to update the logic from a previous discussion
From the solution given in the previous discussions, I want to update the logic to show the average of 5 days a week, and only exclude days that are holidays which land on a weekday
Best Answer
-
In order to do that, you would need to fill in the missing data. The best place to do this would most likely be in your ETL combined with a date dimension. This will help you make sure you have data for every single day of the week.
You can also wrap your column inside of an IFNULL() to replace Nulls with Zero
David Cunningham
** Was this post helpful? Click Agree 😀, Like 👍️, or Awesome ❤️ below **
** Did this solve your problem? Accept it as a solution! ✔️**1
Answers
-
Hi @shreeb ,
You can add a case statement to narrow the data used in the beast mode code. For example, if you want to see Monday - Friday as the 5 days, then you could modify your code like this:
SUM(SUM(CASE WHEN WEEKDAY(ProductionScheduleDate) BETWEEN 2 AND 6 THEN Orders END) FIXED(BY AssignedTo, ProductionScheduleDate - WEEKDAY(ProductionScheduleDate)))
/
AVG(COUNT(DISTINCT CASE WHEN WEEKDAY(ProductionScheduleDate) BETWEEN 2 AND 6 THEN ProductionScheduleDate END) FIXED(BY AssignedTo, ProductionScheduleDate - WEEKDAY(ProductionScheduleDate)))0 -
Good call out @shreeb , that example does not call out holidays. You can always add in other conditions in the case statement to include the specific holidays. The down side of this method is that you would need to update the code each year with the new holidays.
Another really common method is to place the date & holiday logic into an ETL to create a column that indicates when the ProductionScheduleDate is a weekend or holiday. This can be done through a mapping table if you have one, or through a formula tile.
The benefit here would be that you would be able to simplify the case statement to reference the new column. In this example we will call our new column "include dates", and this is how the code would look once the new column is created.
SUM(SUM(CASE `include dates’ = 1 THEN Orders END) FIXED(BY AssignedTo, ProductionScheduleDate - WEEKDAY(ProductionScheduleDate))) / AVG(COUNT(DISTINCT CASE `include dates’ = 1 THEN ProductionScheduleDate END) FIXED(BY AssignedTo, ProductionScheduleDate - WEEKDAY(ProductionScheduleDate)))
0 -
even if i am adding the holiday condition - since there is no data for a particular day, its taking only those days of the week that has a value.
0 -
So i asked the user, the by default want to find average for the week - total sqft / 5. and only exclude holidays for that week.
0 -
In order to do that, you would need to fill in the missing data. The best place to do this would most likely be in your ETL combined with a date dimension. This will help you make sure you have data for every single day of the week.
You can also wrap your column inside of an IFNULL() to replace Nulls with Zero
David Cunningham
** Was this post helpful? Click Agree 😀, Like 👍️, or Awesome ❤️ below **
** Did this solve your problem? Accept it as a solution! ✔️**1 -
@david_cunningham - i tried the ETL with date dimension. Will keep you posted!
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