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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.