Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Flag transactions based on multiple rows

Hi, I'm trying write a DAX measure to flag transactions based on the account number and whether the amount is a debit or a credit. I've pasted some sample data with the desired result below. The criteria for flagging a TxNo as unusual is if [Acct] starts with a 4 and [Credit] <> 0, AND there is another line with that TxNo that has a [Debit] <> 0 to any [Acct] that is not 1501, 1601, or starts with "10".

 

In other words, for each TxNo, if there's a Credit to an Acct starting with a 4, AND a Debit to any account that starts with 10, or equals 1501 or 1601, it should be marked as not unusual on each row of the TxNo. A Debit to any other Acct is unusual and should be marked Yes. 

 

    Desired Result
TxNoAcctDebitCreditUnusualEntry
140000500No
110005000No
240000400Yes
220004000Yes
340000600Yes
310004500Yes
350001500Yes
420001000No
410000100No
410002000No
420000200No
5400301000No
5150110000No
640010750Yes
615001500Yes
610016000Yes
740000250Yes
715022500Yes
  • Anonymous,

     

    Try this measure:

     

    Unusual Entry = 
    VAR vTxNo =
        MAX ( Table1[TxNo] )
    VAR vDebit =
        FILTER (
            ALL ( Table1 ),
            Table1[TxNo] = vTxNo
                && Table1[Debit] <> 0
                && NOT (
                    LEFT ( Table1[Acct], 2 ) = "10"
                        || Table1[Acct] IN { "1501", "1601" }
                )
        )
    VAR vCredit =
        FILTER (
            ALL ( Table1 ),
            Table1[TxNo] = vTxNo
                && Table1[Credit] <> 0
                && LEFT ( Table1[Acct], 1 ) = "4"
        )
    VAR vResult =
        IF ( COUNTROWS ( vDebit ) > 0 && COUNTROWS ( vCredit ) > 0, "Yes", "No" )
    RETURN
        vResult

     

     

1 Reply

  • Anonymous,

     

    Try this measure:

     

    Unusual Entry = 
    VAR vTxNo =
        MAX ( Table1[TxNo] )
    VAR vDebit =
        FILTER (
            ALL ( Table1 ),
            Table1[TxNo] = vTxNo
                && Table1[Debit] <> 0
                && NOT (
                    LEFT ( Table1[Acct], 2 ) = "10"
                        || Table1[Acct] IN { "1501", "1601" }
                )
        )
    VAR vCredit =
        FILTER (
            ALL ( Table1 ),
            Table1[TxNo] = vTxNo
                && Table1[Credit] <> 0
                && LEFT ( Table1[Acct], 1 ) = "4"
        )
    VAR vResult =
        IF ( COUNTROWS ( vDebit ) > 0 && COUNTROWS ( vCredit ) > 0, "Yes", "No" )
    RETURN
        vResult