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.
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
- 10.6K All Categories
- 8 Connect
- 918 Connectors
- 250 Workbench
- 477 Transform
- 1.8K Magic ETL
- 69 SQL DataFlows
- 478 Datasets
- 218 Visualize
- 260 Beast Mode
- 2.1K Charting
- 12 Variables
- 88 Cards, Dashboards, Stories
- 19 Automate
- 356 APIs & Domo Developer
- 89 Apps
- 3 Workflows
- 20 Predict
- 5 Jupyter Workspaces
- 15 R & Python Tiles
- 249 Distribute
- 65 Domo Everywhere
- 243 Scheduled Reports
- 21 Manage
- 42 Governance & Security
- 191 Product Ideas
- 1.2K Ideas Exchange
- 11 Community Forums
- 27 Getting Started
- 14 Community Member Introductions
- 55 Community News
- 4.5K Archive