Forum Discussion

shiggs8's avatar
shiggs8
Frequent Visitor
4 years ago
Solved

Add calculated column based on the matching values in other columns

Hi, I am looking to create a calculated column based on the rows in 4 other columns. So what I want to do is if store no, order no, customer no and date are the same, and if 'Bad Debt Amount' >0 in any of those matching rows, put 'Bad Debt' in both of those rows for the 'Trans Type Calc', otherwise put 'Trans Type'

StoreOrder NoCustomer NoAmountBad Debt AmountDate/TimeTrans TypeTrans Type Calc
2254356455015/07/2021 08:00SaleBad Debt
2254356450615/07/2021 08:00CancelledBad Debt
313573237016/07/2021 08:00SaleSale
437774159017/07/2021 08:00RefundRefund

 

Thanks in advance!

  • shiggs8 , create new column like

     

     

    new column =
    var _sum = calculate(sum([Bad Debt Amount]), allexcept(Table, [store no],[order no],[customer no] ,[date]))
    return
    if(_sum >0 , "Bad Debt",[Trans Type])

2 Replies

  • shiggs8 , create new column like

     

     

    new column =
    var _sum = calculate(sum([Bad Debt Amount]), allexcept(Table, [store no],[order no],[customer no] ,[date]))
    return
    if(_sum >0 , "Bad Debt",[Trans Type])

  • selimovd's avatar
    selimovd
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hey shiggs8 ,

     

    yes, that's possible.

    You can first check for the maximum number for the same Store, Order, etc.

    If this number is > 0 then you can return "Bad Debt" and otherwise the Trans Type. Try the following calculated column:

    Trans Type Calc NEW =
    VAR vBadDebt =
        CALCULATE(
            MAX( myTable[Bad Debt Amount] ),
            ALLEXCEPT(
                myTable,
                myTable[Store],
                myTable[Order No],
                myTable[Customer No],
                myTable[Date/Time]
            )
        )
    RETURN
        IF(
            vBadDebt > 0,
            "Bad Debt",
            myTable[Trans Type]
        )

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis