Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ThaddeusB
Helper I
Helper I

Find new (non-carryover) clients within date range

I have a calendar slicer for user input which does not have a relationship to my data table.  User will select a minimum and maximum date to form a range such a 1/1/2018 - 1/31/2018

 

I have table for client #s with start and end dates.  The same # can have multiple start and end dates.

 

I want to find "new" clients who started service within the date range.  The complication is that I want to count a client as long as they began service after the start date and did not have a service that was ongoing at the start of the period.  So service in previous periods are ignored.

 

Some sample data to illustrate:

 

ClientIDStart dateEnd date
112/30/20171/5/2018
11/10/20181/18/2018
11/28/20182/2/2018
212/1/201712/12/2017
21/5/20181/12/2018
31/12/20181/19/2018
31/27/20183/3/2018
411/5/20171/21/2018
42/3/20182/10/2018
512/20/20172/2/2018

With this data, the correct count would be 2 (clients #2 & 3).   


I can filter the table down to relevant services in the period via:

VAR minDate = MIN ( 'Calendar'[Date] )
VAR maxDate = MAX ( 'Calendar'[Date] )
FILTER ( data,  ( data[Start date] <= maxDate && data[End date] >= minDate ) )
 
but can't seem to figure out how to get that filter into an expression that gets the calculation I want.
3 REPLIES 3
v-yuta-msft
Community Support
Community Support

Hi ThaddeusB,

 

"I want to find "new" clients who started service within the date range. The complication is that I want to count a client as long as they began service after the start date and did not have a service that was ongoing at the start of the period. So service in previous periods are ignored." 

 

<--- Your requirement is not so clear. For example, could you please clarify why clientID 1 doesn't meet the condition. Could you give more details about the logic?

 

Regards,

Jimmy Tao


@v-yuta-msft wrote:

Hi ThaddeusB,

 

"I want to find "new" clients who started service within the date range. The complication is that I want to count a client as long as they began service after the start date and did not have a service that was ongoing at the start of the period. So service in previous periods are ignored." 

 

<--- Your requirement is not so clear. For example, could you please clarify why clientID 1 doesn't meet the condition. Could you give more details about the logic?

 

Regards,

Jimmy Tao


 

@v-yuta-msft  Thanks for your reply.  I would be happy to (try to) clarify.  A "new" client is one who started a service after the start date of the period and didn't also have a service ongoing at the start of the period.  Client 1 does not qualify as new in January because he had a service from 12/30/17-1/5/18.

 

One possible logic would be 

1) Filter down to services in the selected period (using filter I posted or something similar):

ClientIDStart dateEnd date
112/30/20171/5/2018
11/10/20181/18/2018
11/28/20182/2/2018
21/5/20181/12/2018
31/12/20181/19/2018
31/27/20183/3/2018
411/5/20171/21/2018
512/20/20172/2/2018

2) Find the minimum entry date by client in the filtered set

ClientIDStart dateEnd date
112/30/20171/5/2018
21/5/20181/12/2018
31/12/20181/19/2018
411/5/20171/21/2018
512/20/20172/2/2018

3) Count the number of minimum entry dates on or after the selected period start date.

ClientIDStart dateEnd date
21/5/20181/12/2018
31/12/20181/19/2018

So I came up with the following that appears to work:

 

VAR minDate = MIN('Calendar'[Date])
VAR maxDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
COUNT(Data[ClientId]),
FILTER(
NATURALLEFTOUTERJOIN(Data,
SUMMARIZE(
FILTER(
Data,
Data[Start date] <= maxDate && Sheet1[End date] >= minDate
),
Data[Client Id],
"MinD",
MIN(Data[Start date])
)
), [minD]=[Start date] && [minD])>=minDate
)
)
 
Let me know if you know a more efficient way to achieve the goal.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.