Calculating the Running Maximum
Is there some way to calculate a running maximum either through ETL/SQL?
I have employee hiring data and I want to check if an employee newly hired into a position is a backfill or a new growth. This classification is part of others that are used in existing charts showing how many active/hired/job change/terminations employees we have each month. My strategy at the moment is the calculate the count of employees in each position each month. I want to use this count in finding the running maximum which I will compare to the current count to determine if it a new position or a backfill position.
I'm open to hearing other strategies to approach this problem as well.
Comments
-
Hi @Crisocir
You can utilize a windowing function to calculate the rolling maximum.
MAX(MAX(`JDL Count`)) OVER(ORDER BY `Batch Date`)
Window functions in analyzer require a feature switch. Talk to your CSM if you don't already have them enabled in your instance.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
@Crisocir be super careful with the aggregate functions particularly MAX() and COUNT(DISTINCT) OVER ...
they will work for ONE card with an axis but as soon as you change the axis it'll probably yield the wrong result.
So, while you may get the 'right number' when you look at MAX(MAX()) by Department and Year, if you wanted to do a summary of just MAX(MAX()) by Year (across all departments) or MAX(MAX()) by Region, you'll get the 'wrong result' because of how Window functions work and calculate.
I know that sounds vague, but window functions are complex and if you've never worked with them before they do have a lot of caveats. I did a long form webinar on the topic here. https://www.youtube.com/watch?v=eifSYZIcPzg&t=2247s
Your best bet is to avoid aggregating the data and instead try to capture your data at the POSITION level (not employee) where your granularity is one row per month per position. Then add an 'isNewHire' flag to capture if it's the first month an employee was with the company, and an 'isNewPosition' flag for if a new position was created.
If you have to use window functions, you can use sum(sum()) of the binary flags, and that will ALWAYS give the 'right answer'.
Hope that helps.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"1
Categories
- All Categories
- 1.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 293 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 97 SQL DataFlows
- 607 Datasets
- 2.1K Magic ETL
- 3.8K Visualize
- 2.4K Charting
- 707 Beast Mode
- 49 App Studio
- 39 Variables
- 667 Automate
- 170 Apps
- 446 APIs & Domo Developer
- 44 Workflows
- 7 DomoAI
- 33 Predict
- 13 Jupyter Workspaces
- 20 R & Python Tiles
- 391 Distribute
- 111 Domo Everywhere
- 274 Scheduled Reports
- 6 Software Integrations
- 115 Manage
- 112 Governance & Security
- Domo Community Gallery
- 31 Product Releases
- 9 Domo University
- 5.3K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 103 Community Announcements
- 4.8K Archive