The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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.
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.
Row | Acct# | Bag | Person | Bag Combo | Need this |
1 | 11 | HR | Bob | HR-TN | FALSE |
2 | 11 | TN | Sue | TN | TRUE |
3 | 12 | HR | Bob | HR-TN | FALSE |
4 | 12 | TN | Bob | HR-TN | FALSE |
5 | 13 | TN | Sue | TN | FALSE |
6 | 13 | Sales | Hans | SGEN | FALSE |
7 | 14 | HR | Bob | HR-TN | FALSE |
8 | 15 | HR | Bill | HR | FALSE |
9 | 15 | TN | Sue | TN | FALSE |
10 | 16 | HR | Sally | HR-TN | FALSE |
11 | 16 | TN | Sally | HR-TN | FALSE |
12 | 16 | Sales | Hans | SGEN | FALSE |
13 | 17 | HR | Bill | HR | TRUE |
14 | 17 | TN | Sally | HR-TN | FALSE |
Solved! Go to Solution.
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], "," )
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
You are awesome. Thanks much @Zubair_Muhammad , the solution worked perfectly. Is it possible to show the person with the same bag when True?
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], "," )