Choosing first and last month in BM
Is there a way to use fixed functions or something else to grab the first date that appears and the last date that appears?
I am trying to calculate yearly attrition. I have it by month but adding up or avg the monthly % is not mathematically correct. I need to get the first month and last month's values within a certain timeframe. I did do some hard-coded stuff in ETLs but people want to be able to choose the timeframe and other filters in order to calculate a yearly value.
Essentially I have what is below. I want to grab min month value1 and max month value 1 and add them together. After that, I would want to add up everything from value2 and then divide that by the sum of the min + max date of value 1.
Start Date End Date Value1 Value 2
1/1/22 1/31/22 500 2
2/1/22 2/28/22 510 8
3/1/22 3/31/22 505 3
4/1/22 4/30/22 507 1
**If this answer solved your problem be sure to like it and accept it as a solution!
Best Answer
-
Earliest date for the year
MIN(MIN(`Date`)) OVER (PARTITION BY YEAR(`Date`))
Latest date for the year
MAX(MAX(`Date`)) OVER (PARTITION BY YEAR(`Date`))
Remove the partition clause if you want it across your entire dataset.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1
Answers
-
Earliest date for the year
MIN(MIN(`Date`)) OVER (PARTITION BY YEAR(`Date`))
Latest date for the year
MAX(MAX(`Date`)) OVER (PARTITION BY YEAR(`Date`))
Remove the partition clause if you want it across your entire dataset.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Thank you @GrantSmith exactly what I needed!
**If this answer solved your problem be sure to like it and accept it as a solution!
0 -
@GrantSmith so I am able to use those calculations separately but when I try to add them together in the same BM it does the weird blank error thing.
**If this answer solved your problem be sure to like it and accept it as a solution!
0 -
You're getting a blank because your CASE statement is likely returning a NULL value. Are you displaying you data split by anything other than Company?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
I used your solution and it worked for me when using the min function but for whatever reason it is returning nothing with the max function. Any idea why? @GrantSmith
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.8K Visualize
- 2.5K Charting
- 738 Beast Mode
- 56 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 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