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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sd_kevin
Advocate II
Advocate II

How to return records only if the record falls between Start and End Dates

Hi,

 

Is it possible to only return records from a table where the records has a StartDate and an EndDate that is between the user selected date from another unrelated table?  For example when the user selects a value (date) from a slicer linked to another table and the SELECTEDVALUE is between the StartDate and EndDate.  

 

Slicer will be based on this tableSlicer will be based on this table

 

This will be where the records will be returned fromThis will be where the records will be returned from

 

At this point I am not even sure how to join/create a relationship between these two tables.  I don't neccessary need to have any relationship between the two tables, but just need some way to use what was selected from the EffDateTable to filter what is returned on the OnLeaveTable (and also another table).

 

TIA!

 

Kevin

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@sd_kevin  - So this is like what I call a Complex Selector. In your case it could go like this:

 

Measure = 
  VAR __Date = SELECTEDVALUE('EffDateTable'[Effective Date])
  VAR __LeavdDate = MAX('OnLeaveTable'[LeavdDate])
  VAR __ReturnDate = MAX('OnLeaveTable'[ReturnDate])
RETURN
  IF(__LeavdDate >= __Date && __ReturnDate <= __Date,1,0)

 You can then use your OnLeave column in a table visualization and then Measure in the Filters pane for example.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
sd_kevin
Advocate II
Advocate II

@Greg_Deckler @mahoneypat @sevenhills @amitchandak 

 

Thank you all for your solutions and quick responses!!!  I love this community!  I learned so much just reviewing all the solutions you provided.  All the solutions worked.  Since @Greg_Deckler responded first I will mark his as the solution.

 

Thank you all again.  Your help was very much appreciated!

 

Warm regards,

 

Kevin

amitchandak
Super User
Super User

@sd_kevin , Try a measure like

Measure =
var _max = maxx(allselected(EffDateTable),EffDateTable[EffectiveDate])
return
Calculate(Count(Epluyees), OnLeaveTable[LeaveDate]<= _max, OnLeaveTable[ReturnDate]>=_max)

mahoneypat
Employee
Employee

Yes.  With no relationship between the tables, make a slicer with the EffectiveDate and a table visual with your onleave column (and leave and return date if desired), and this measure:

 

SelectedDateInRange = var selecteddate = selectedvalue(EffDateTable[EffectiveDate])

return Calculate(Countrows(OnLeaveTable), OnLeaveTable[LeaveDate]<= selecteddate, OnLeaveTable[ReturnDate]>=selecteddate)

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Optional: If you are taking above @mahoneypat, use today date for null Return date

 

var selecteddate = selectedvalue(EffDateTable[Effective Date])

return Calculate(Countrows(OnLeaveTable), OnLeaveTable[LeaveDate]<= selecteddate, IF(ISBLANK(OnLeaveTable[ReturnDate]), TODAY(), OnLeaveTable[ReturnDate]) >=selecteddate)

@sevenhills 

 

Thank you so much for this option!  I definitely used it!

 

Warm regards,

 

Kevin

Greg_Deckler
Super User
Super User

@sd_kevin  - So this is like what I call a Complex Selector. In your case it could go like this:

 

Measure = 
  VAR __Date = SELECTEDVALUE('EffDateTable'[Effective Date])
  VAR __LeavdDate = MAX('OnLeaveTable'[LeavdDate])
  VAR __ReturnDate = MAX('OnLeaveTable'[ReturnDate])
RETURN
  IF(__LeavdDate >= __Date && __ReturnDate <= __Date,1,0)

 You can then use your OnLeave column in a table visualization and then Measure in the Filters pane for example.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Thank you the solution and quick response!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors