Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
shiggs8
Frequent Visitor

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!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@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])

View solution in original post

2 REPLIES 2
selimovd
Super User
Super User

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
 
amitchandak
Super User
Super User

@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])

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.