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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Saxon10
Post Prodigy
Post Prodigy

Lookup find and match from one table to another table

Hi,

 

I have a two tables are Data and Report.

 

In data table the following columns are code, Type1, state1, Type2, state2 and report table are code and type.

 

In report table the both types in one column (Apple, Orange) but data table the type columns as two (separated Apple and Orange).

 

I would like to pick the state from data table into report table based on the code and type. In report table some time the type is blanks or XXX.

 

If type column is XXX then return X and if type column is Blanks then return No otherwise return state.

I am looking for New calculated column option to achieve my desired result.

 

Data:

 

CODETYPE1STATE1TYPE2STATE2
X1APPLEM1ORANGEN1
X2APPLEM2ORANGEN2
X3APPLEM3ORANGEN3
X4APPLEM4ORANGEN4
X5APPLEM5ORANGEN5
X6APPLEM6ORANGEN6
X7APPLEM7ORANGEN7
X8APPLEM8ORANGEN8
X9APPLEM9ORANGEN9
X10APPLEM10ORANGEN10

 

Report

CODETYPESTATE
X1APPLEM1
X1APPLEM1
X1APPLEM1
X1ORANGEN1
X1ORANGEN1
X1ORANGEN1
X1ORANGEN1
X1ORANGEN1
X1XXXX
X1XXXX
X1XXXX
X1XXXX
X1 NO
X1 NO
X1 NO
X2APPLEM2
X2APPLEM2
X2APPLEM2
X2ORANGEN2
X2ORANGEN2
X2ORANGEN2
X2ORANGEN2
X2ORANGEN2

 

Saxon10_0-1633773604814.png

 

2 ACCEPTED SOLUTIONS

@Saxon10 

Where you see blank, either you can replace them with null in Power Query or modify the code as follows

NEW STATE = 
VAR TYPE1 = LOOKUPVALUE( Data[STATE1], Data[TYPE1] , Report[TYPE] , Data[CODE] , [CODE] )
VAR TYPE2 = LOOKUPVALUE( Data[STATE2], Data[TYPE2] , Report[TYPE] , Data[CODE] , [CODE] )
RETURN
IF(
    Report[TYPE])  = " " ,  "NO",
    COALESCE( TYPE1 , TYPE2 , "X" )
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

smpa01
Community Champion
Community Champion

@Saxon10  can you please try this

 

Column =
VAR _0 =
    DISTINCT (
        UNION (
            SUMMARIZE ( Data, Data[CODE], Data[STATE1], Data[TYPE1] ),
            SUMMARIZE ( Data, Data[CODE], Data[STATE2], Data[TYPE2] )
        )
    )
VAR _1 =
    MAXX (
        FILTER (
            _0,
            [CODE] = EARLIER ( Report[CODE] )
                && [TYPE1] = EARLIER ( Report[TYPE] )
        ),
        [STATE1]
    )
VAR _2 =
    CALCULATE ( MAX ( Report[TYPE] ) )
VAR _3 =
    SWITCH ( TRUE (), _2 = "XXX", "X", _2 = BLANK (), "NO", _1 )
RETURN
    _3

 

smpa01_0-1633809348745.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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
========================

View solution in original post

5 REPLIES 5
smpa01
Community Champion
Community Champion

@Saxon10  can you please try this

 

Column =
VAR _0 =
    DISTINCT (
        UNION (
            SUMMARIZE ( Data, Data[CODE], Data[STATE1], Data[TYPE1] ),
            SUMMARIZE ( Data, Data[CODE], Data[STATE2], Data[TYPE2] )
        )
    )
VAR _1 =
    MAXX (
        FILTER (
            _0,
            [CODE] = EARLIER ( Report[CODE] )
                && [TYPE1] = EARLIER ( Report[TYPE] )
        ),
        [STATE1]
    )
VAR _2 =
    CALCULATE ( MAX ( Report[TYPE] ) )
VAR _3 =
    SWITCH ( TRUE (), _2 = "XXX", "X", _2 = BLANK (), "NO", _1 )
RETURN
    _3

 

smpa01_0-1633809348745.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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
========================

@smpa01 and @Fowmy

 

Thanks for your reply and help both solutions working well. 

Fowmy
Super User
Super User

@Saxon10 

You can add the following column to your table. 

NEW STATE = 
VAR TYPE1 = LOOKUPVALUE( Data[STATE1], Data[TYPE1] , Report[TYPE] , Data[CODE] , [CODE] )
VAR TYPE2 = LOOKUPVALUE( Data[STATE2], Data[TYPE2] , Report[TYPE] , Data[CODE] , [CODE] )
RETURN
IF(
    ISBLANK(Report[TYPE]) , "NO",
    COALESCE( TYPE1 , TYPE2 , "X" )
)

 

Fowmy_0-1633776111140.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group


Thanks for your reply and help. I using extacly the same code but I am receving different result. Can you please advise why? My expect result is No but formula giving X. 

 

 

Saxon10_0-1633790252222.png

 

@Saxon10 

Where you see blank, either you can replace them with null in Power Query or modify the code as follows

NEW STATE = 
VAR TYPE1 = LOOKUPVALUE( Data[STATE1], Data[TYPE1] , Report[TYPE] , Data[CODE] , [CODE] )
VAR TYPE2 = LOOKUPVALUE( Data[STATE2], Data[TYPE2] , Report[TYPE] , Data[CODE] , [CODE] )
RETURN
IF(
    Report[TYPE])  = " " ,  "NO",
    COALESCE( TYPE1 , TYPE2 , "X" )
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.