Forum Discussion
Lookup value if date is between two dates
- Anonymous7 years ago
I don't think you've told us all about the model... I suspect there are relationships between the two tables based on the date fields.
Try this
CreatedInSprint = var __date = WorkItems[fields_SystemCreatedDate] return MAXX( FILTER( Sprints; AND( Sprints[attributes_startDate] <= __date, __date <= Sprints[attributes_finishDate] ) ), Sprints[SprintNo] )
This should work correctly on the assumption that there is always at most one sprint returned by the logical condition in FILTER. If there happen to be many, then the maximum SprintNo will be returned.
Best
Darek
I don't think you've told us all about the model... I suspect there are relationships between the two tables based on the date fields.
Try this
CreatedInSprint = var __date = WorkItems[fields_SystemCreatedDate] return MAXX( FILTER( Sprints; AND( Sprints[attributes_startDate] <= __date, __date <= Sprints[attributes_finishDate] ) ), Sprints[SprintNo] )
This should work correctly on the assumption that there is always at most one sprint returned by the logical condition in FILTER. If there happen to be many, then the maximum SprintNo will be returned.
Best
Darek
- Anonymous7 years agoNot applicable
Hi Darek
Thank you for your rapid reply. Your assumption was correct and it works out of the box.
Just to follow-up on the model.
The following relationships exist (between Dates and Sprints) and (between Dates and WorkItems)
From date in Dates to attributes_startDate in Sprints (1:*) and (cross filter direction: Both)
From date in Dates to attributes_finishDate in Sprints (1:*) and (cross filter direction: Both)
From date in Dates to fields_SystemCreatedDate in WorkItems (1:*) and (cross filter direction: Both)
Best regards
Martin
- Anonymous7 years agoNot applicable
I want to warn you:
Be extremely careful with a model that has both-ways cross-filtering enabled. This is very DANGEROUS and you may end up calculating things you won't understand. The best people in the world of DAX say that both-ways cross-filtering should be enabled IF AND ONLY IF it's strictly necessary and when you understand all the consequences. I'd advise that you revise your model and remove cross-filtering as much as possible. If the model becomes at one point ambiguous (because, for instance, you add some tables to it and create relationships) and the engine does not detect it (which is not uncommon), then you'll be in deep trouble.
You've been warned.
Best
Darek
- Anonymous7 years agoNot applicable
I see, thank you for the insights on this topic.
I will change my model with this in mind.
Best regards
Martin
- Krd6032064 years agoFrequent Visitor
Hi @Anonymous, would you be able to help with a similar question. I have a table in which i am looking to return true/false for a date which comes after the Date_from column and before the Date_until column date. I have tried a regular DAX expression of
InRangeDate = and(DELNOTES[DELNOTE_DATE]>=DELNOTES[DATE_FROM],DELNOTES[DELNOTE_DATE]<=DELNOTES[DATE_UNTIL]) but this only returns TRUE in all instances. I have then tried to hard code the date for a given accounting period using this expression
InRange = and(DELNOTES[DELNOTE_DATE]>=date(2021,11,22),DELNOTES[DELNOTE_DATE]<=date(2021,12,26)) - this works perfectly, but is not dyamic. The issue appears to be with the calculation but am at a loss as to how to get around it. Any help would be most helpful.