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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
WGordon
Frequent Visitor

Creating a reusable table filter

My problem can be split into two I suppose. The original issue, I would like to have a Calendar filter my main contract table, such that if I select a date then only contracts which started before and finished after that date show up.
That's easy enough to do and apply in an individual measure using filters. But I am going to reuse this in many measures, which leads to me to two questions:
1. Is there a way to define a table filter which can be reused in multiple measures. E.g. A measure which is a filter and I define it once and reuse it in many subsequent measures (I know you can't return a table in a measure but that's how I imagine it.)?
 2. For this specific case, is there a better way of defining this relationship between the Calendar table and the Contract table? Maybe I don't need to use measures/ filters at all?

I think I know the answer to both of these questions but it feels like reusing the same filter code in a dozen or so measures is bad practice and will be a pain if I need to go back through and change anything. It would be much better to just define the filter once and reuse it where it's needed.

Thanks in advance,

WG

1 ACCEPTED SOLUTION
WGordon
Frequent Visitor

So, having thought about it for 10 more minutes, I decided to Create a Measure which doesn't return a filter itself but can be used in a filter expression. Therefore the logic still gets reused.
The filter returns True if the Max date in the Calendar is > than the Contract start date and the Min Date of the Calendar is < the Contract End Data.
So if the Calendar isn't filtered, all contracts come through.
If the Calendar is filtered to say a month then all Contracts which are active for any time in that Month come through.
If you have selected a single Date then exactly contracts which are active on that date will come throuh.

Is_Within_Date_Range =
VAR Max_Calendar = MAX('Calendar'[Date])
VAR Min_Calendar = MIN('Calendar'[Date])
VAR Max_End = Max(Contract[Expiry].[Date])
VAR Min_Start = Min(Contract[Inception].[Date])

RETURN
AND(Max_Calendar >= Min_Inception, Min_Calendar <= Max_Expiry)

I would still be interested to know if there's a better way of doing this.

Cheers,
WG

View solution in original post

2 REPLIES 2
v-angzheng-msft
Community Support
Community Support

Thank you for sharing, I think the above measure is very effective. Could you please mark your post as Answered since it is working now? It will help the others in the community find the solution easily if they face the same problem with you. Thank you.

WGordon
Frequent Visitor

So, having thought about it for 10 more minutes, I decided to Create a Measure which doesn't return a filter itself but can be used in a filter expression. Therefore the logic still gets reused.
The filter returns True if the Max date in the Calendar is > than the Contract start date and the Min Date of the Calendar is < the Contract End Data.
So if the Calendar isn't filtered, all contracts come through.
If the Calendar is filtered to say a month then all Contracts which are active for any time in that Month come through.
If you have selected a single Date then exactly contracts which are active on that date will come throuh.

Is_Within_Date_Range =
VAR Max_Calendar = MAX('Calendar'[Date])
VAR Min_Calendar = MIN('Calendar'[Date])
VAR Max_End = Max(Contract[Expiry].[Date])
VAR Min_Start = Min(Contract[Inception].[Date])

RETURN
AND(Max_Calendar >= Min_Inception, Min_Calendar <= Max_Expiry)

I would still be interested to know if there's a better way of doing this.

Cheers,
WG

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.