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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

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 and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors