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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Mahi1827
Resolver I
Resolver I

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

Hi,

 

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.

 

Status<>close
close date <= @EndDate
or
Status=close
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.


Thanks,
Mahi1827..

 

 

2 REPLIES 2
v-deddai1-msft
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

v-deddai1-msft
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

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.