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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Svante109
Frequent Visitor

IF then else function

My problem is - I've got two columns of serialnumbers. Most of them have 5 digits, but I have serialnumbers with 2,3, and 4 digits. In one column the serialnumber has leading zeros, while the other doesn't. This mess up my data when merging the columns to extract data from one query to another, because query doesn't link 00630 with 630 e.g.

 

I have tried adding the zeros to the non-zero-column, with this formula

 

= Table.AddColumn(#"Replaced Value3", "unit serial no", each if [unit seriel no_]=3 then "00"[unit seriel no_] else if [unit seriel no_]=4 then "0"[unit seriel no_] else if [unit seriel no_]=2 then "000" else [unit seriel no_])

 

It just returns the serialnumber it self. I want it to take 630 and return 00630.

5 REPLIES 5
RolandsP
Resolver IV
Resolver IV

Please make sure that Data Type of the column is Text

@Svante109 seems like type of your uniserialno_ column is number, you need to check the length of the value in this column and then concatenate with number of zeros to make it proper length. 

 

In following example, replace [Key] column with your column number and add more if condition to check length 

 

(if Text.Length(Number.ToText([Key])) = 1 then "000" else
if Text.Length(Number.ToText([Key])) = 2 then "00" else
if Text.Length(Number.ToText([Key])) = 3 then "0" else "")
& Number.ToText([Key])

 

 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k 

 

I will try these tomorrow, thank you. I'm pretty sure that both columns are text though.

 

Hi @parry2k 

 

When using the formula, it returns a column with just errors, unfortunately.

 

@Svante109 it worked for me, share what error you are getting and waht formula you exactly used.

 

Also share what is the data type of your columns



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors