cancel
Showing results for 
Search instead for 
Did you mean: 
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
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors