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
MDePauw
New Member

How to add a between filter based on columns in other table?

Hello,

 

I'm trying to create a dynamic last 7 day filter in PowerBI, but after several hours I can't seem to get it working.

 

I'm currently thinking of the current table setup (unlinked tables in the model)

DIM_CALENDAR: Basic calendar table
DIM_CALENDAR_2: Contains 1 row having a Startdate and a EndDate. (Date will be selected in slicer so only 1 row is returned)

I want to filter the data in DIM_CALENDAR to only get the dates between the StartDate and Enddate in DIM_CALENDAR_2.

How can this be achieved in PowerBI?

I was trying to create a flag using the following DAX calculation but this doesn't seem to work.

BetweenDates = IF (
'DIM_CALENDAR'[Date] > CALCULATE ( MAX ( DIM_CALENDAR_2[StartDate] ); ALLSELECTED ( DIM_CALENDAR_2 ) )
&&
'DIM_CALENDAR'[Date] < CALCULATE ( MAX ( DIM_CALENDAR_2[EndDate] ); ALLSELECTED ( DIM_CALENDAR_2 ) )
; 1; 0 )

If I add the three individual columns (Start_Date, End_date & date) in a list the three correct values appear.

The flag however is not calculated correctly.

 

Can someone please assist or point me in the right direction?

 

Thanks in advance,

M

 

1 REPLY 1
v-yuezhe-msft
Employee
Employee

@MDePauw,

Create a measure instead of column using DAX below. If it doesn't return your expected result, please share dummy data and post expected result.

BetweenDates = IF (
MIN('DIM_CALENDAR'[Date])> CALCULATE ( MAX ( DIM_CALENDAR_2[StartDate] ); ALLSELECTED ( DIM_CALENDAR_2 ) )
&&
MAX('DIM_CALENDAR'[Date]) < CALCULATE ( MAX ( DIM_CALENDAR_2[EndDate] ); ALLSELECTED ( DIM_CALENDAR_2 ) )
; 1; 0 )



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.