Power Query: M 'if' Formula Help

Tuta

Board Regular
Joined
Nov 6, 2008
Messages
85
Office Version
  1. 365
Platform
  1. Windows
All,

Code:
= Table.AddColumn(Data0, "Custom", each if[Column1]="UPDATED" then "UPDATED" else "NEW")

Trying to add a custom column that drops in UPDATED if column 1 contains the word, if it doesn't then I want to drop in NEW. Not sure how to use wildcards in here either.





thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Currently - it drops in NEW in each row.

Column one actually has UPDATED as the first word in some rows, nothing in others.

So:
UPDATED Boring Boring Text Row1
Boring Boring Text Row2
Boring Boring Text Row3
UPDATED Boring Boring Text Row4


So in my super fancy new custom, I'm trying for:
UPDATED
NEW
NEW
UPDATED



Thanks!
john
 
Upvote 0
you're using = so it would have to match without any additional data in the field. If Updated is always the first word can you not search for the LEFT(Column, 7) = "Updated"
 
Upvote 0
Text.PositionOf
and
Text.PositionOfAny

should help you accomplish that. You might want to read more about those M functions :)
 
Upvote 0
Miguel -- I most definitely need to read more.

Code:
= Table.AddColumn(#"Changed Type", "New_Updated", each if Text.Contains([Column1], "UPDATED") then "UPDATED" else "NEW")

The above is what I ended up with to get to where I needed (so far).




I'm going to leave this here for myself when I inevitably forget this again (and for others)
Learn About Power Query Formulas -- Click HERE
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top