Forum

New value based on ...
 
Notifications
Clear all

New value based on what previous column value starts with...

4 Posts
3 Users
0 Reactions
80 Views
(@amar247)
Posts: 3
Active Member
Topic starter
 

Hi all

I am very new to Power Query and am struggling with the M language it uses. I see the potential it has so have embarked on a project that will need me to utilise it if I am to succeed. 

Very long story short...I have a bunch of alphanumeric values in one column - some start with a letter, some a number. If the value starts with a number, then I need the new column to add a zero to the beginning of it (and copy across), otherwise just copy the existing value across as is.

I would really appreciate it if someone could point me in the right direction...example in Excel attached >>> 

PQ.PNG

 

Regards

Amar

 
Posted : 11/06/2020 3:44 pm
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Amar,

Yes Power Query is a fantastic tool but for this problem you don't need to use it.  You can achieve what you want with functions :

=IFERROR(IF(NUMBERVALUE(LEFT(B2,1)),"0"&B2,B2),B2)

Please see attached file.

regards

Phil

 
Posted : 11/06/2020 8:10 pm
(@amar247)
Posts: 3
Active Member
Topic starter
 

Hi Phil

Thank you for coming back to me so quickly, much appreciated.

The reason I need that task to be done in Power Query is so that it is automated. The raw dataset I am using is vast and in bad shape, so there are steps previous to that, that PQ is already preforming (perfectly) and there will be steps afterwards.

The first two digits of that field represent a Department and I have a mapping table that I will pull in afterwards on the basis of those two digits - along several other things before I can complete the model.

I am sure that formula will come in handy at some point though, thanks!

 

Regards

Amar

 
Posted : 12/06/2020 11:41 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Amar,

This is why it's very important to give the whole picture of what you're trying to do and why.

You can use this Power Query formula in a 'Custom Column':

= if Value.Is(Number.FromText(Text.Start([Column1],1)), type number) then "0"&[Column1] else [Column1] otherwise [Column1])

 

Mynda

 
Posted : 12/06/2020 7:50 pm
Share: