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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Lookup in Power BI using DAX

Hi All,

I have a scenario where I have two table.

Table A: Users and Access field

2.PNG

Table B: Users and AuthVariable

1.PNG

Now the logic is , for the user in Table B, look for the "AuthVariable" value. If the value is "Z1" , then look for the "Access" field in Table A and assign the user with all the "Access" values which start with "1"(eg: 11,15 form Table A).

If the value is "Zall", assign all the "Access" values to that user (eg: 11,28,15,55,63,64,41,36), and if the value is "Z5", assign all the "Access" values from Table A which starts with 5(55) against that user.

 

These values can be appended to Table A or create a new table Table C.

 

Could you please help with a approach.

 

Thanks

Poojitha

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Thanks @Anonymous , this was fun.

 

TableC = 
    VAR __AccessCodes = DISTINCT('TableA'[Access])
    VAR __TableB = 'TableB'
    VAR __TableA = 'TableA'
    VAR __Table = GENERATE(FILTER(__TableB,[AuthVariable]<>"Zall"),__AccessCodes)
    VAR __TableZall = GENERATE(FILTER(__TableB,[AuthVariable]=="Zall"),__AccessCodes)
    VAR __TableZallFinal = SELECTCOLUMNS(__TableZall,"User",[User],"Access",[Access])
    VAR __TableFinal = 
        SELECTCOLUMNS(
            FILTER(
                ADDCOLUMNS(
                    __Table,
                    "__AuthVariable",RIGHT([AuthVariable],1),
                    "__Access",LEFT([Access],1)
                ),
                [__Access] = [__AuthVariable]
            ),
            "User",[User],
            "Access",[Access]
        )
RETURN
    UNION(__TableA, __TableFinal, __TableZallFinal)


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

Thanks @Anonymous , this was fun.

 

TableC = 
    VAR __AccessCodes = DISTINCT('TableA'[Access])
    VAR __TableB = 'TableB'
    VAR __TableA = 'TableA'
    VAR __Table = GENERATE(FILTER(__TableB,[AuthVariable]<>"Zall"),__AccessCodes)
    VAR __TableZall = GENERATE(FILTER(__TableB,[AuthVariable]=="Zall"),__AccessCodes)
    VAR __TableZallFinal = SELECTCOLUMNS(__TableZall,"User",[User],"Access",[Access])
    VAR __TableFinal = 
        SELECTCOLUMNS(
            FILTER(
                ADDCOLUMNS(
                    __Table,
                    "__AuthVariable",RIGHT([AuthVariable],1),
                    "__Access",LEFT([Access],1)
                ),
                [__Access] = [__AuthVariable]
            ),
            "User",[User],
            "Access",[Access]
        )
RETURN
    UNION(__TableA, __TableFinal, __TableZallFinal)


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you for the quick response. I will try to implement the same and update the results here.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.