1

I have an Appointments table with the columns MemberID and DateOfConsultation. Each member may have more than 1 consultation, with the same or different dates. I want to get a rolling 3 month period, where for the latest month, I get the data relevant to all the consultations that happened in that month and the 2 months before and I want to count, for each 3 month period, the number of distinct members and separately the number of distinct members who had more than 1 consultation in that 3 month period. Not the distinct number per month, but for the 3 month rolling periods. How can I achieve this? I am using SSMS 20.2 with Azure Synapse.

I tried joining the table onto itself, where the date of consultation is within the last 3 months and that does seem to give me the list of unique IDs, but I can't figure out a way to merge it with the list of unique IDS that have had more than 1 consultation (row in the original table), where both values are showing against the latest month. Hope that made any sense..

[EDIT] I added the tool I am using and sample data. For the reporting month of December 2024 for example, I would expect the results to be 4 unique members and 3 unique members with more than 1 appointment (over the months of October, November and December).

Here's the sample data:

MemberID DateOfConsultation MonthStart
170092800 22/10/2024 01/10/2024
163861342 21/10/2024 01/10/2024
170623737 21/10/2024 01/10/2024
170759670 21/10/2024 01/10/2024
170092800 21/10/2024 01/10/2024
170759670 03/12/2024 01/12/2024
163861342 06/12/2024 01/12/2024
170759670 17/12/2024 01/12/2024
170759670 04/11/2024 01/11/2024
163861342 04/11/2024 01/11/2024
170759670 15/11/2024 01/11/2024
170759670 18/11/2024 01/11/2024
170759670 26/11/2024 01/11/2024
170759670 29/11/2024 01/11/2024
8
  • 3
    Sample data and expected results are essential. Commented Feb 27 at 13:16
  • 1
    This might help you get a start dbfiddle.uk/eKJSCh-o Commented Feb 27 at 13:44
  • 1
    Which dbms are you using? (Different products have different possibilities.) Commented Feb 27 at 14:21
  • 1
    Now added this info @jarlh Commented Feb 27 at 18:48
  • 2
    Please add expected results. Is this closer to what you need? dbfiddle.uk/P8M0HMI- Commented Feb 27 at 19:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.