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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gavin007
Helper V
Helper V

Try Otherwise in M doesn't work when multiple rows meet the condition

I am trying to replace the internal sales account number with the external sales accounts number when the ExtInt="I" (indicating an internal sales), I use try Dax to search each row in source query where it meets the following conditions,

1. internal sales  OrderNO_Revised is the same as external sales

2. ExtInt="C" 

 

When the condition is met, the replacement happen. 

e.g. OrderNo_Revised=60S027143 with Customer Code_Revised IT000007 has been replaced with external customer code CL0002633.

 

My problem is when there are two identical OrderNo_Revised in external sale lines (yellow retangle) the Try formula doesn't work (red retangle shows the internal customer code is still IC0002851 as opposed to CL0002844). Can anyone help or suggest alternative to 

 

Capture.PNG

I upload the folder in onedrive, you need to reconnect the source file when you refresh the query. the try script is in Recco query.

https://1drv.ms/u/s!Aig3EWdV94jKgfAJ74rRtH77XZfbkA?e=Jt1dIa

 

2 REPLIES 2
Fowmy
Super User
Super User

@gavin007 

You have used try---otherwise, it hides the error. When you have multiple results, your code breaks. Remove your code and try to add a new column using the following code, if multiple results are returned, I get the MAX of it.

= Table.AddColumn(Source, "Custom", each 
if [ExtInt]="I" then  
 let Order = [OrderNo_Revised] ,
   Cust =  List.Max(Table.SelectRows(Source, each [ExtInt] = "C" and [OrderNo_Revised] = Order )[Customer Code_Revised])
 in if Cust=null then [Customer Code_Revised] else Cust
else
[Customer Code_Revised]
)

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi Fowmy, it is working in the samples. However, when i put in actual daily sales files with more than 80,000 rows,  it loops through the source every time it evaluate the formula. it takes more than 8 hours and still counting to apply the query.

 

Is there a way to make it more efficiency. like don't evaluate the external customer, only the internal.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.