Forum Discussion
How do I get a value within a range
Hi,
I have the following table (tblPIListing):
PI Start Date End Date
PI1 01/03/2024 03/26/2024
PI2 03/27/2024 07/02/2024
PI3 07/03/2024 09/24/2024
PI4 09/25/2024 12/31/2024
I have another table(OnlyFeatureswithParentKey) and need to get 2 PIs, one based on the Start Date and the other on End Date:
Key Start Date End Date PIStartAlignment PIEndAlignment
123 01/03/2024 04/29/2024 PI1 PI2
456 07/04/2024 09/24/2024 PI3 PI3
Here Is my logic:
Here is the solution that works for me:
PIDateThatEndDateFallsIn =var matchingqtr = FILTER(tblPIListing,OnlyFeaturesWithParentKey[DueDate] >= tblPIListing[StartDate] && OnlyFeaturesWithParentKey[DueDate] <= tblPIListing[EndDate])var CountQtr = COUNTROWS(matchingqtr)return IF(CountQtr>=1,MAXX(matchingqtr,tblPIListing[EndDate]),BLANK())
6 Replies
- Greg_DecklerCommunity Champion
- EaglesTonyPost Prodigy
That looks like what I need.
But not sure how that solves my issue to select PI2 instead of PI1 based on:
PI1 01/03/2024 03/26/2024
PI2 03/27/2024 07/02/2024
- rajendraongole1Super User
Hi EaglesTony - can you please try the below logic using lookupvalue
PIStartAlignment =LOOKUPVALUE(PITest[PI],PITest[Start Date],CALCULATE(MAX(PITest[Start Date]),FILTER(PITest,PITest[Start Date] <= OnlyFeatureswithParentKey[Start Date] &&PITest[End Date] >= OnlyFeatureswithParentKey[Start Date])))PIEndAlignment1 =LOOKUPVALUE(PITest[PI],PITest[Start Date],CALCULATE(MAX(PITest[Start Date]),FILTER(PITest,PITest[Start Date] <= OnlyFeatureswithParentKey[ End Date] &&PITest[End Date] >= OnlyFeatureswithParentKey[ End Date])))Hope it works.- EaglesTonyPost Prodigy
It gave me blank, here is my logic:
PIFeaturesFallsInBasedOnFeaturesDueDate =LOOKUPVALUE(tblPIListing[PI],tblPIListing[EndDate],CALCULATE(MAX(tblPIListing[StartDate]),FILTER(tblPIListing,tblPIListing[StartDate] <= OnlyFeaturesWithParentKey[DueDate] &&tblPIListing[EndDate] >= OnlyFeaturesWithParentKey[DueDate])))- EaglesTonyPost Prodigy
This is giving me blank value for the following:
OnlyFeaturesWithParentKey[Start Date]="06/17/2024"
OnlyFeaturesWithParentKey[DueDate] ="08/31/2024"
It is giving me 7/2/2024 instead of 9/24/2024.
Here is my logic:PIFeaturesFallsInBasedOnFeaturesDueDate =
LOOKUPVALUE(
tblPIListing[PI],
tblPIListing[EndDate],
CALCULATE(
MAX(tblPIListing[EndDate]),
FILTER(
tblPIListing,
OnlyFeaturesWithParentKey[DueDate] >= tblPIListing[StartDate] && OnlyFeaturesWithParentKey[DueDate] <= tblPIListing[EndDate])
)
)I even tried this:, but it gives me an error "Expressions that yield variant data-type cannot be used to define calculated columns", but it seems to do what I want, if I don't find anything it should return "N/A"
var matchingqtr = FILTER(tblPIListing,OnlyFeaturesWithParentKey[DueDate] >= tblPIListing[StartDate] && OnlyFeaturesWithParentKey[DueDate] <= tblPIListing[EndDate])var CountQtr = COUNTROWS(matchingqtr)return IF(CountQtr>=1,MAXX(matchingqtr,tblPIListing[EndDate]),"N/A")