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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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)

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

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)

@ 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!:
The Definitive Guide to Power Query (M)

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors