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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
rpinxt
Solution Sage
Solution Sage

Custom Column Formula Help

Ok so I made this Custom Colum in Query Editor:

rpinxt_0-1653908811554.png

Now this works just fine however I have 1 extra requirement.

So where it takes the first 2 characters of [Material] in 90% of the cases these are letters.

However there are a few materials that start with numbers.

 

How can I ammend this formula:

=if [Mat.Type] = "ZRAW" then Text.Start([Material],2) else "X"

 

So that when the Materials starts with a number (any number) it returns "LB" and for all the others just the 2 first characters of the Material.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rpinxt ,

 

Please try this formula:

 

if [Mat.Type]="ZRAW" then try Number.From(Text.Start([Material],2)) otherwise "LB" else "X"

 

vstephenmsft_0-1654240757751.png

vstephenmsft_1-1654240765315.png

PS: I helped you move your post to the Power Query forum. Posting in the correct forum next time will help you solve the problem faster.

 

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.

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @rpinxt ,

 

Please try this formula:

 

if [Mat.Type]="ZRAW" then try Number.From(Text.Start([Material],2)) otherwise "LB" else "X"

 

vstephenmsft_0-1654240757751.png

vstephenmsft_1-1654240765315.png

PS: I helped you move your post to the Power Query forum. Posting in the correct forum next time will help you solve the problem faster.

 

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.

 

HotChilli
Community Champion
Community Champion

Sure, you can do it without adding the column.

Personally I divide and conquer when attacking a problem, it's easier to debug and separate out parts of the logic.

One thing about Power Query steps is that you can add columns to help, get other results and then remove the helper columns.

 

I understand but in a large dataset would adding all these extra columns not lead to worse performance (and  I do understand that complex formulas would do the same but still)

 

Also...how would that formula look 😊....because there does not seem to be an IFERROR formula othere then try / otherwise....but that would not fit very good in my if formulas.....

HotChilli
Community Champion
Community Champion

You could find out whether the Material starts with a number by adding a column using the 

Number.FromText(  ,,) function.  You can pass the first character of Material to this function (which you already know how to do using Text.Start.)

This will show error or a number.  
If you want to make it a bit neater, wrap it with try..otherwise to handle the error gracefully.

Once you have this column working you can implement the logic you desire in the final column : for example,

if there is a number then "LB" else first two chars.

----

See if you can progress this and I'll help if you have problems

 

Ok this sounds interesting @HotChilli .

But would I really need an extra column?

 

Could I not add the part of Number.FromText to this formula?

=if [Mat.Type] = "ZRAW" then Text.Start([Material],2) else "X"

 

Something like =if [Mat.Type] = "ZRAW" then
                            Iferror(Number.FromText([Material]) then "LB" else
                            Text.Start([Material],2)

                            else "X"

 

Or would that not work because of the double If and double else?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.