Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Resolver I
Resolver I

How to set date range in direct query based on multiple dates comparisons



I have 3 tables one is "summary" and other is "details" and another one is "date" table

open date, close date are two date columns from summary table and status column from details table and date column from date table

here i have logic and  i would like to create date range in power bi based on opend date and close date conditions

Note  that @end date used in multiple cases.


close date <= @EndDate
open date >= @StartDate and open date <= @EndDate


in power BI i am trying to create two date slicers, one for start date and another for end date


in modeling open date and close date columns are mapped to date coulmn in date table, staus column from deatils table is mapped to status column in summary table


so finally in power BI i am using below approach to get date range.


1st date slicer for start date:
as per logic  for start date slicer,i have considered date column from date table for open date and i set status=close in slicer visaul filter and applied date slection is "After"  in slicer settngs


2nd date slicer for end date
as per logic for end date slicer, i have considered date column from date table for close date and created below calcualted column and set as 1 in slcier visual filter and finally set selection is "Before"  in slicer settngs

End date filter = if( (MAX(open date)>=RELATED([Date])&& calculate(max(status),filter(status,(Status="Close"))
|| (MAX(close date)<=RELATED([Date]) && calculate(max(status),filter(status,(Status<>"Close")) ,1,0)

note that here @enddate is considered in multiple cases with OR condition.


as per above approach the date range is not working as expected so

please suggest with best approach to apply date range where the end date considered in multiple scenarios and also please suggest udpated dax code for possible solution   Or  please suggest can we get required date range by using only single date slicer by using measures...?

Thanks for your time, suggestions and help in advance.




Community Support
Community Support

Hi @Mahi1827 ,


You requirement can be achieved by measure. But without your sample data, I can't help you well. Would you please show us sample pbix by onedrive for business if possible?


Best Regard,

Dedmon Dai

Community Support
Community Support

Hi @Mahi1827 ,


Would you please inform us more detailed information( your

 data and expected output (by OneDrive for Business)) if possible? Then we will help you more correctly.


Please do mask sensitive data before uploading.


Thanks for your understanding and support.


Best Regard,

Dedmon Dai

Helpful resources

PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors