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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
YuvalD
New Member

Find if a date is within multiple periods

Hi,

I am looking for a way to evaluate if a date of a visit at customer falls within a period that the customer was active. 
I have the following structure:

VisitData  
CustomerIDVisitDateResult
115/01/2022Yes
116/05/2022Yes
101/02/2022No
201/06/2022Yes
301/12/2022No

 

CustomerHistory  
CustomerIDActive StartActive End
101/01/202230/01/2022
101/05/202230/05/2022
201/05/2022 
301/06/2022

30/11/2022

 

So for each visitdate, I want to check in Customer History table and get a result. 

For example -

CustomerID #1 has 3 visits, and 2 periods of activity. only two visits are valid and one is not in any valid period.

CustomerID #2 has 1 visit and 1 period which is not over yet (No End date)

CustomerID #3 has 1 visit and 1 period and the visit is out of the period therefore not valid. 

 

How can I calculate the 'Result' Field considering there are multiple possible periods for each customer ?

Many thanks !!

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @YuvalD 

 

try to add a column in the visit table with this:

Result2 = 
VAR _customer = [CustomerID]
VAR _date = [VisitDate]
VAR _count =
COUNTROWS(
    FILTER(
        CustomerHistory,
        CustomerHistory[CustomerID] = _customer
            &&CustomerHistory[ActiveStart]<=_date
            &&(CustomerHistory[ActiveEnd]>=_date||CustomerHistory[ActiveEnd]=BLANK())
    )
)
RETURN
IF(  _count>=1, "Yes", "No")

 

i tried and it worked like this:

FreemanZ_0-1671706112731.png

p.s. no relationship is needed.

View solution in original post

2 REPLIES 2
YuvalD
New Member

Hi @FreemanZ,
That worked perfectly. 
Thanks !

FreemanZ
Super User
Super User

hi @YuvalD 

 

try to add a column in the visit table with this:

Result2 = 
VAR _customer = [CustomerID]
VAR _date = [VisitDate]
VAR _count =
COUNTROWS(
    FILTER(
        CustomerHistory,
        CustomerHistory[CustomerID] = _customer
            &&CustomerHistory[ActiveStart]<=_date
            &&(CustomerHistory[ActiveEnd]>=_date||CustomerHistory[ActiveEnd]=BLANK())
    )
)
RETURN
IF(  _count>=1, "Yes", "No")

 

i tried and it worked like this:

FreemanZ_0-1671706112731.png

p.s. no relationship is needed.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.