Forum Discussion
Identifying Similar Transactions in the same table
I am trying to identify similiar transactions in from a table.
For example if I had the table below Table1
| Transaction | Employee | Vendor | Date | Amount |
| 1 | A | Amazon | 10/1/2023 | $ 71.00 |
| 2 | B | Costco | 8/15/2023 | $ 19.46 |
| 3 | C | Amazon | 9/15/2023 | $ 65.46 |
| 4 | A | Amazon | 10/1/2023 | $ 72.00 |
| 5 | A | Costco | 10/1/2023 | $ 75.00 |
| 6 | B | Costco | 9/15/2023 | $ 70.00 |
| 7 | B | Costco | 9/16/2023 | $ 72.00 |
| 8 | A | Amazon | 10/2/2023 | $ 73.00 |
| 9 | C | Amazon | 9/26/2023 | $ 91.66 |
| 10 | C | Costco | 7/4/2023 | $ 89.62 |
| 11 | C | Amazon | 7/27/2023 | $ 11.29 |
| 12 | A | Amazon | 9/17/2023 | $ 80.08 |
| 13 | A | Amazon | 8/3/2023 | $ 10.19 |
| 14 | A | Costco | 7/26/2023 | $ 10.94 |
| 15 | C | Walmart | 9/23/2023 | $ 14.40 |
Would there be a way in to create a Table2 in PowerQuery that identfies matches that meet certain criteria? For example if I wanted to identify all transactions $70-$75 from the same employee to the same vendor within 10 days of each other. The second table might look like this?
| Transaction1 | Transaction2 |
| 1 | 4 |
| 1 | 8 |
| 4 | 1 |
| 4 | 8 |
| 6 | 7 |
| 7 | 6 |
| 8 | 1 |
| 8 | 4 |
Any help is appreciated. RIght now I was able to make DAX functions to show if there are matching transactions for any given transactions, but I think it'd be more useful for my purposes if I was able to list out the pairs.
Using one of the GENERATE functions is useful here. For example,
Similar = GENERATE ( FILTER ( Transactions, Transactions[Amount] >= 70 && Transactions[Amount] <= 75 ), VAR _Trans = Transactions[Transaction] VAR _Emp = Transactions[Employee] VAR _Vend = Transactions[Vendor] VAR _Date = Transactions[Date] VAR _Matches_ = FILTER ( Transactions, Transactions[Transaction] <> _Trans && Transactions[Employee] = _Emp && Transactions[Vendor] = _Vend && ABS ( DATEDIFF ( Transactions[Date], _Date, DAY ) ) <= 10 ) RETURN SELECTCOLUMNS ( _Matches_, "Transaction2", Transactions[Transaction] ) )
1 Reply
- AlexisOlsonSuper User
Using one of the GENERATE functions is useful here. For example,
Similar = GENERATE ( FILTER ( Transactions, Transactions[Amount] >= 70 && Transactions[Amount] <= 75 ), VAR _Trans = Transactions[Transaction] VAR _Emp = Transactions[Employee] VAR _Vend = Transactions[Vendor] VAR _Date = Transactions[Date] VAR _Matches_ = FILTER ( Transactions, Transactions[Transaction] <> _Trans && Transactions[Employee] = _Emp && Transactions[Vendor] = _Vend && ABS ( DATEDIFF ( Transactions[Date], _Date, DAY ) ) <= 10 ) RETURN SELECTCOLUMNS ( _Matches_, "Transaction2", Transactions[Transaction] ) )