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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Neha94
Regular Visitor

Duplicate value vlookup with date comparison in specified period with power query

Hello,

I have 2 datasets - Set A and Set B.

Set A has Issue description and issue date along with product code. Set B has product code along with product validity start date and product validity end date. Since validation process requires revalidation of product after validity has ended, there are multiple validity start date and end dates in Set B. The final outcome which I want is for every issue in Set A, does the Set A issue date fall between any of the validity periods?

Please find example below-

Neha94_0-1641488968138.png

 

 

Set ASet ASet A
Issue Date C1Issue C2Product code C3Is issue date between validity period?(Outcome)explanation
1-May-21leakageAYesAs it falls in second validity period of A (Mar'21-Mar'22)
6-Jul-21rattle soundBNoIssue after both validity for B
21-Sep-21electrical failureCYesIssue within second validty of C (Aug'21-Aug'22)
15-Oct-21brokenDNoIssue before validity of D
     
Set B C1Set B C2Set B C3
Product codeValidity StartValidity end  
A1-Dec-191-Dec-20  
A3-Mar-213-Mar-22  
A6-Jun-146-Jun-15  
B9-Sep-149-Sep-15  
B10-Oct-1610-Oct-17  
C4-Apr-194-Apr-20  
C8-Aug-218-Aug-22  
D29-Oct-2129-Oct-22  
     
2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

How about this as a calculated column?

VAR CurrProd = SetA[Product code]
VAR CurrDate = SetA[Issue Date]
VAR SetBFiltered =
    FILTER (
        SetB,
        SetB[Prodcut code] = CurrProd
            && SetB[Validity Start] <= CurrDate
            && SetB[Validity End] >= CurrDate
    )
RETURN
    IF ( ISEMPTY ( SetBFiltered ), "No", "Yes" )

View solution in original post

smpa01
Super User
Super User

@Neha94 use the following measure, works beyond any relationship

 

Measure =
VAR _issue =
    MAX ( SetA[Issue Date] )
VAR _filt =
    CALCULATE (
        MAX ( SetB[Product code] ),
        FILTER ( SetB, _issue >= SetB[Validity Start] && _issue <= SetB[Validity end] ),
        TREATAS ( { MAX ( SetA[Product code] ) }, SetB[Product code] )
    )
RETURN
    IF ( ISBLANK ( _filt ) = TRUE (), FALSE (), TRUE () )

 

 

smpa01_0-1641491524346.png

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

5 REPLIES 5
smpa01
Super User
Super User

@Neha94 use the following measure, works beyond any relationship

 

Measure =
VAR _issue =
    MAX ( SetA[Issue Date] )
VAR _filt =
    CALCULATE (
        MAX ( SetB[Product code] ),
        FILTER ( SetB, _issue >= SetB[Validity Start] && _issue <= SetB[Validity end] ),
        TREATAS ( { MAX ( SetA[Product code] ) }, SetB[Product code] )
    )
RETURN
    IF ( ISBLANK ( _filt ) = TRUE (), FALSE (), TRUE () )

 

 

smpa01_0-1641491524346.png

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Yes. This worked. Thanks a lot. Can you help me understand how does it check all the different validity periods for a single product? Thanks again!

Hi @Neha94 

 

Measure =
VAR _issue =
    MAX ( SetA[Issue Date] ) --- what is the currently visible SetA[Issue Date] from the filter context
VAR _filt =
    CALCULATE (
        MAX ( SetB[Product code] ),
        --- after all the necessary filtering give the max date ---step3
        FILTER (
            SetB,
            _issue >= SetB[Validity Start]
                && _issue <= SetB[Validity end]
        ),
        -- filter SetB so that SetB[Validity Start]<=_issue<=SetB[Validity end]  ---step1
        TREATAS (
            { MAX ( SetA[Product code] ) },
            SetB[Product code]
        ) -- also once the above filtering is done, only consider SetA[Product code] in the current filter context----step2
    )
RETURN
    IF ( ISBLANK ( _filt ) = TRUE (), FALSE (), TRUE () )

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
AlexisOlson
Super User
Super User

How about this as a calculated column?

VAR CurrProd = SetA[Product code]
VAR CurrDate = SetA[Issue Date]
VAR SetBFiltered =
    FILTER (
        SetB,
        SetB[Prodcut code] = CurrProd
            && SetB[Validity Start] <= CurrDate
            && SetB[Validity End] >= CurrDate
    )
RETURN
    IF ( ISEMPTY ( SetBFiltered ), "No", "Yes" )

This worked. Thanks a lot. I am new to power bi and it didnt occur to me to use a filter instead of fetching the validity date with lookup. 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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