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
jjku
Frequent Visitor

Help on handling errors?

I cannot figure out how to insert the IF xxx[HasError]  else  xxx then  into this statement.

 

 

 

= Table.AddColumn(#"Added Custom9", "Entity", each ( let currentEntryNoKey = [Entry_No_Key] in Table.SelectRows(All_Vendor_Ledger, each [Entry_No_Key] = currentEntryNoKey)) 
{0}[Vendor_Name])

 

 

 

Basically, if there is an error, I just want it to return blank. If there is no error, then return the {0}[Vendor_Name]

 

 

1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

OK, if you just want a value from that table, or null each time there is an error, I would do it like this, so there are no scope issues.  Add a new step, name it EntryKeyList, then in the formula bar, type:

= List.Buffer(#"Added Custom9"[Entry_No_Key])

 

Add a new step, name it NewThing (or whatever), then in the formula bar:

= Table.AddColumn(EntryKey, "Entity" each try Table.SelectRows(All_Vendor_Ledger, each List.Contains([Entry_No_Key], EntryKeyList)){0}[Vendor_Name] otherwise null)

 

--Nate

 

 

 

Entity = Table.AddColumn(


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

7 REPLIES 7
watkinnc
Super User
Super User

OK, if you just want a value from that table, or null each time there is an error, I would do it like this, so there are no scope issues.  Add a new step, name it EntryKeyList, then in the formula bar, type:

= List.Buffer(#"Added Custom9"[Entry_No_Key])

 

Add a new step, name it NewThing (or whatever), then in the formula bar:

= Table.AddColumn(EntryKey, "Entity" each try Table.SelectRows(All_Vendor_Ledger, each List.Contains([Entry_No_Key], EntryKeyList)){0}[Vendor_Name] otherwise null)

 

--Nate

 

 

 

Entity = Table.AddColumn(


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
jjku
Frequent Visitor

I will try this fix and report back. Thanks!

jjku
Frequent Visitor

Yes. I guess my problem is where do I put the Try and the Else.. I can't seem to figure that out.

 

I did try this:

 

= Table.AddColumn(#"Added Custom9", "Entity", each ( let currentEntryNoKey = [Entry_No_Key] in Table.SelectRows(All_Vendor_Ledger, each [Entry_No_Key] = currentEntryNoKey)), 
try {0}[Vendor_Name] otherwise "null")

 

but now I get a We cannot convert the value "null" to type Type.

jjku
Frequent Visitor

I changed it to this...

 

= Table.AddColumn(#"Added Custom9", "Entity", each ( let currentEntryNoKey = [Entry_No_Key] in Table.SelectRows(All_Vendor_Ledger, each [Entry_No_Key] = currentEntryNoKey)),
try {0}[Vendor_Name] otherwise Null.Type)

 

it seems to work, but my new problem is that the null results says TABLE, and not null.

Not Null.Type, just null. 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
jjku
Frequent Visitor

When i put null.. the result for all the null say  table. But nothing is in that table. 

 

I can't get my head around the TYPE. 

 

jjku_0-1625771068118.png

 

AlexisOlson
Super User
Super User

The standard method in M is with "try" ... "otherwise". In your case, "try xxx otherwise null" with return xxx if there isn't an error and a null otherwise.

 

https://docs.microsoft.com/en-us/power-query/handlingerrors

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.

Top Solution Authors
Top Kudoed Authors