Forum Discussion

deepu299's avatar
deepu299
Icon for Advocate V rankAdvocate V
7 years ago
Solved

Lookup from Same Table and return true or false

Hi, I need help with DAX to return TRUE or FALSE from the following data set. For Acct# = 11, I want to check other rows with same Acct#, and if Persons are different, I want to compare Bag with Bag Combo (this is multiple bags separates with hyphen) and if exists then return TRUE, otherwise FALSE. 

  • Are there other entries in the data set that have this account number? (i.e., is there more than one bag on a given account?) 
  • If Yes, does the Bag of the Owner on the current row overlap with the Bag Combos carried by any of the people on the other rows for that account?


for Row 1 below, 11=11, Bob<>Sue, HR doesnt exist in Sue's Bag Combo so return FALSE

for Row 2, 11=11, Sue <> Bob, TN exists in Bob's Bag Combo (HR-TN) so return TRUE. 



RowAcct#BagPersonBag ComboNeed this
111HRBobHR-TNFALSE
211TNSueTNTRUE
312HRBobHR-TNFALSE
412TNBobHR-TNFALSE
513TNSueTNFALSE
613SalesHansSGENFALSE
714HRBobHR-TNFALSE
815HRBillHRFALSE
915TNSueTNFALSE
1016HRSallyHR-TNFALSE
1116TNSallyHR-TNFALSE
1216SalesHansSGENFALSE
1317HRBillHRTRUE
1417TNSallyHR-TNFALSE
  • deepu299 

     

    This works with your sample data.

    Assuming yourtablename is Table1

     

    Calculated Column =
    VAR myrow = [Row]
    VAR Act = [Acct#]
    VAR mybag = [Bag]
    VAR myperson = [Person]
    VAR SameAcc_DifRow =
        ADDCOLUMNS (
            FILTER ( Table1, [Acct#] = Act && [Row] <> myrow && [Person] <> myperson ),
            "BagFound", SEARCH ( mybag, [Bag Combo], 1, 0 )
        )
    RETURN
        COUNTROWS ( FILTER ( SameAcc_DifRow, [BagFound] > 0 ) ) > 0
    
  • Hi deepu299 

     

    Try this column to get Person with same bag.

    See file attached as well

     

    PersonWithSameBag =
    VAR myrow = [Row]
    VAR Act = [Acct#]
    VAR mybag = [Bag]
    VAR myperson = [Person]
    VAR SameAcc_DifRow =
        ADDCOLUMNS (
            FILTER ( Table1, [Acct#] = Act && [Row] <> myrow && [Person] <> myperson ),
            "BagFound", SEARCH ( mybag, [Bag Combo], 1, 0 )
        )
    RETURN
        CONCATENATEX ( FILTER ( SameAcc_DifRow, [BagFound] > 0 ), [Person], "," )
    

     

3 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Icon for Community Champion rankCommunity Champion

    deepu299 

     

    This works with your sample data.

    Assuming yourtablename is Table1

     

    Calculated Column =
    VAR myrow = [Row]
    VAR Act = [Acct#]
    VAR mybag = [Bag]
    VAR myperson = [Person]
    VAR SameAcc_DifRow =
        ADDCOLUMNS (
            FILTER ( Table1, [Acct#] = Act && [Row] <> myrow && [Person] <> myperson ),
            "BagFound", SEARCH ( mybag, [Bag Combo], 1, 0 )
        )
    RETURN
        COUNTROWS ( FILTER ( SameAcc_DifRow, [BagFound] > 0 ) ) > 0
    
    • deepu299's avatar
      deepu299
      Icon for Advocate V rankAdvocate V

      You are awesome. Thanks much Zubair_Muhammad , the solution worked perfectly. Is it possible to show the person with the same bag when True?

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Icon for Community Champion rankCommunity Champion

        Hi deepu299 

         

        Try this column to get Person with same bag.

        See file attached as well

         

        PersonWithSameBag =
        VAR myrow = [Row]
        VAR Act = [Acct#]
        VAR mybag = [Bag]
        VAR myperson = [Person]
        VAR SameAcc_DifRow =
            ADDCOLUMNS (
                FILTER ( Table1, [Acct#] = Act && [Row] <> myrow && [Person] <> myperson ),
                "BagFound", SEARCH ( mybag, [Bag Combo], 1, 0 )
            )
        RETURN
            CONCATENATEX ( FILTER ( SameAcc_DifRow, [BagFound] > 0 ), [Person], "," )