How to dynamically return the latest value for a filtered date range

I have a card for Top 20 Selling Styles that includes Sales, Units Sold, and Quantity On Hand. It is powered by Sales and Inventory datasets that are updated weekly with a date tied to each week.
The person I am building this card for will be utilizing a date filter to change the card to the time period they want to see. For the Quantity On Hand however, I need to only show the latest week of the time period this person selects, since summing up inventory every week doesn't make sense. If filtering to "Previous Quarter," I only want to show them the Quantity On Hand value of the final week within that quarter.
I don't think this could be done within the dataflow since the value will be changing depending on the period selected (correct me if wrong please), so I tried a Beast Mode. I got close, but it isn't exactly what I was needing. First I created a definition of the latest week by building the below:
Max Date: MAX(MAX(Date
)) OVER ()
This returns the final date of the filtered period. I then built this to use it:
CASE WHEN Date
= Max Date
THEN SUM(Quantity On Hand
)
ELSE 0
END
It works, but the issue with this is that the Date column has to be on the card for the formula to be utilized or else it just returns 0, which defeats the purpose of using the date filters to create the report.
Best Answer
-
That's right, you mentioned that it was a top 20 report at the top. I believe that you can still get it to work with the following changes:
- Include the Style in your fixed functions: SUM(SUM(Sales) FIXED (BY Style))
- Sort on Date Descending, then Sales FIXED
- Limit rows to 20
0
Answers
-
Hi @Mickey - If you come at this from the completely opposite direction you can get to a solution that works. Here are the steps:
- Create FIXED functions for Sales and Units Sold. Example: SUM(SUM(`Sales`) FIXED ())
- Place "Date", "Sales FIXED", "Units Sold FIXED", and "Quantity On Hand" in your table card.
- You should have the sum of Sales and the sum of Units Sold repeated on each row at this point, as well as each discrete Date and Quantity On Hand value
- Make sure to graph by Day
- Sort by Date Descending
- Limit Rows to 1
- In General, go to the Hide Columns property and enter 1 to hide the Date column
1 -
@ggenovese Limiting the rows to 1 removes the purpose of the card since I'm listing the Top 20 Styles by Sales during the period the client filters to, so I'll need to sort by Sales. It also only returns the sum value the Quantity On Hand of whatever the Style ID at the top of all rows is, not the sum of the final week of On Hand of the filtered period
0 -
That's right, you mentioned that it was a top 20 report at the top. I believe that you can still get it to work with the following changes:
- Include the Style in your fixed functions: SUM(SUM(Sales) FIXED (BY Style))
- Sort on Date Descending, then Sales FIXED
- Limit rows to 20
0 -
@ggenovese Okay that worked. Thank you so much for your help!
1
Categories
- All Categories
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 664 Datasets
- 120 SQL DataFlows
- 2.3K Magic ETL
- 825 Beast Mode
- Visualize
- 2.6K Charting
- 89 App Studio
- 46 Variables
- Automate
- 197 Apps
- 489 APIs & Domo Developer
- 94 Workflows
- 24 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 119 Domo Everywhere
- 283 Scheduled Reports
- 11 Software Integrations
- Manage
- 144 Governance & Security
- 11 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 116 Community Announcements
- 5K Archive