Tracking members duration, with overlaping memberships.
I have the following case.
One member can have multiple memberships at the same time, and can cancel one or many, and after that, resume or enroll in a new one. How can I track the day a member has been with our company? I have the column with the membership name that is not in the photo.
Answers
-
SELECT
MIN(`Create Date`) as 'Member Origination Date'
MAX(`End Date`) as 'Member Termination Date'FROM yourData
GROUP BY(`Member ID`)
Then in your card you filter out anyone who has a Member Termination Date in the past to show only current members.
If I solved your problem, please select "yes" above
0 -
Depending upon your criteria, it may not be as simple as aggregating by group. Consider sample data like this:
Member_ID
Start_Date
End_Date
101
2023-01-01
2023-03-31
101
2023-03-15
2023-06-01
101
2023-07-01
2023-08-01
Some memberships may not overlap. And in other scenarios, you can't group and count each membership and sum them together because that means some of the days would be counted twice for the same member. Unless that is what you wanted.
Member_ID
Start_Date
End_Date
Days
101
2024-01-01
2024-01-31
31
101
2024-01-15
2024-02-15
32
So you would have to merge the overlapping periods / adjacent ranges. Then count the total span of those merged periods.
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0 -
Using the examples I show, I manually count:
January 1, 2023 → June 1, 2023
Includes both start and end dateResult: 152 days
July 1, 2023 → August 1, 2023
Includes both start and endResult: 32 days
January 1, 2024 → February 15, 2024
2024 is a leap yearResult: 46 days
For a total of 230 days.
To solve this I created a SQL query to produce a calendar table. This will hold a single date for a range of my choosing. I exported the table from SQL to Domo.
DECLARE @StartDate DATE = '2010-01-01';
DECLARE @EndDate DATE = '2035-12-31';
WITH Calendar AS (
SELECT @StartDate AS CalendarDate
UNION ALL
SELECT DATEADD(DAY, 1, CalendarDate)
FROM Calendar
WHERE CalendarDate < @EndDate
)
SELECT
CalendarDate,
DATENAME(WEEKDAY, CalendarDate) AS Day_Name,
DATEPART(DAY, CalendarDate) AS Day,
DATEPART(MONTH, CalendarDate) AS Month,
DATENAME(MONTH, CalendarDate) AS Month_Name,
DATEPART(YEAR, CalendarDate) AS Year,
DATEPART(WEEK, CalendarDate) AS Week_Number,
DATEPART(QUARTER, CalendarDate) AS Quarter
FROM Calendar
OPTION (MAXRECURSION 32767);Sample membership as a csv import
Member_ID,Start_Date,End_Date
101,2023-01-01,2023-03-31
101,2023-03-15,2023-06-01
101,2023-07-01,2023-08-01
101,2024-01-01,2024-01-31
101,2024-01-15,2024-02-15Magic ETL using a tile to make sure end dates are not null. So I set these to current date.
On the JOIN condition I used:
And the end result gives me the answer I got when I manually calculated and removed overlaps.
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0
Categories
- All Categories
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 663 Datasets
- 119 SQL DataFlows
- 2.3K Magic ETL
- 823 Beast Mode
- Visualize
- 2.6K Charting
- 86 App Studio
- 46 Variables
- Automate
- 193 Apps
- 483 APIs & Domo Developer
- 87 Workflows
- 23 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 117 Domo Everywhere
- 283 Scheduled Reports
- 11 Software Integrations
- Manage
- 143 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