Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Lookup in Power BI using DAX

Hi All,

I have a scenario where I have two table.

Table A: Users and Access field

Table B: Users and AuthVariable

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

 

 

 

  • 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)

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity 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)
    • Anonymous's avatar
      Anonymous
      Not applicable

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