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

Help converting IFERROR Excel formulas to PowerQuery M

I have a dataset in Excel formatted as a table. I need to add 4 new columns to this table to test some logic. I have the following four Excel formulas in blue font, which I'd like to translate into M and Power Query in Power BI:

column 1 - "Doc ID in PMT? (Y/N) (quick check)" = IFERROR(IF(MATCH([@Document id]],[dataT_PMT.Document Id],0),"Yes","No"),"No")

column 2 - "Intake IDs of Doc IDs in PMT (Y Only)" = IF([@Doc ID in PMT? (Y/N) (quick check)]] = "Yes", [@[Intake id]], "")

column 3 - "Intake IDs of Doc IDs NOT in PMT (N Only)" = IF([@Doc ID in PMT?(Y/N) (quick check)]] = "No", [@[Intake id]], "")

column 4 - "Review Realized? (Intake ID represented in PMT) (Y/N) (Full Check)" = IFERROR(IF(MATCH([@[Intake IDs of Doc IDs in PMT (N Only)]], [Intake IDs of Doc IDs in PMT (Y Only)],0),"Yes"),"No")

 

Of course IFERROR does not work in M. I've tinkered with Try but haven't quite figured out how to implement all the logic above from Excel. Any guidance would be greatly appreciated!

 

Thanks!

Steve

1 ACCEPTED SOLUTION

Hi @s_schwantes 

 

I am not asking you to post anything sensitive, you can't even give some dummy data like this? All the columns you mentioned are in the same table? I don't see why you need all 4 columns...maybe my dummy data can't represent your table

 

Vera_33_0-1626915871260.png

 

Vera_33_1-1626916659320.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lECYSOlWJ1oJSMjMBPGNTYGMiE4NhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Intake id" = _t, ID = _t, #"dataT_PMT.Document Id" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "column1", each if List.Contains(Source[dataT_PMT.Document Id],[ID]) then "Yes" else "No"),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "column2", each if [column1]="Yes" then [Intake id] else ""),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "column3", each if [column1]="No" then [Intake id] else ""),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "column4", each if List.Contains(#"Added Custom2"[column2],[column3]) then "Yes" else "No")
in
    #"Added Custom3"

 

 

View solution in original post

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

Hi @s_schwantes ,

 

use "try....otherwise".

 

try <some code hear that may result in an error> otherwise  <run this code in case of error>

 

note that try and otherwise are NOT capitalized.  Also, no commas are needed.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Vera_33
Resident Rockstar
Resident Rockstar

Hi @s_schwantes 

 

Can you provide some sample data in a format which we can copy? try...otherwise... is the structure, but it depends on what you want, provide some data then we can see if you need it

Hi Vera_33,

Sorry strict company regulations prohibit me from posting any thing other than what I am able to type into the forum. Can't even upload a JPEG or provide link to other cloud storage; eg., Box, DropBox etc. (not accessible).

Thanks,

Steve

Hi @s_schwantes 

 

I am not asking you to post anything sensitive, you can't even give some dummy data like this? All the columns you mentioned are in the same table? I don't see why you need all 4 columns...maybe my dummy data can't represent your table

 

Vera_33_0-1626915871260.png

 

Vera_33_1-1626916659320.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lECYSOlWJ1oJSMjMBPGNTYGMiE4NhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Intake id" = _t, ID = _t, #"dataT_PMT.Document Id" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "column1", each if List.Contains(Source[dataT_PMT.Document Id],[ID]) then "Yes" else "No"),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "column2", each if [column1]="Yes" then [Intake id] else ""),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "column3", each if [column1]="No" then [Intake id] else ""),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "column4", each if List.Contains(#"Added Custom2"[column2],[column3]) then "Yes" else "No")
in
    #"Added Custom3"

 

 

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