The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I want to convert cells under EV that does not contain numbers to "None" and retain those that contains numbers. I tried below formula but "0".."9" portion shows an error. I replaced it with Text.Contains(_, "0123456789") but it changes all the cells to None.
#"Replace None" = Table.TransformColumns(Source", {{"EV", each if Text.Contains(_, "0".."9") then _ else "None"}})
Solved! Go to Solution.
=Table.ReplaceValue(YourTable,"","",(x,y,z)=>if Text.Remove(Text.From(x),{"0".."9"})=x then "None" else x,{"EV"})
nice, thanks so much!
=Table.ReplaceValue(YourTable,"","",(x,y,z)=>if Text.Remove(Text.From(x),{"0".."9"})=x then "None" else x,{"EV"})
Table.TransformColumns(Source, {{"EV", each if Text.PositionOfAny(_, {"0".."9"}) <> -1 then _ else "None"}})
Hi Pete, good day! Actually, there are a lot to be replaced like n\a, N\A, NA, not available, No data, NO DATA, ND, etc. Power Query, as I believe, is case sensitive to I have a lot to add. The users would also erroneously input data that may not be on the list.
Yes, fair enough. Wasn't sure if the example you provided showed all the exception possibilities or not.
PQ is case sensitive, that's why I've used "Text.Lower([EV])" as the comparison value - a neat trick to deal with exactly this issue in PQ.
Looks like @AlienSx has provided a really nice neat solution, so you're sorted anyway 👍
Pete
Proud to be a Datanaut!
Hi @abellanc ,
It's a little bit of a hack, but you may find it way simpler just to replace the "N/A"s with "None", something like this:
Table.ReplaceValue(
PreviousStepName,
each [EV],
each if List.Contains({"na", "n/a"}, Text.Lower([EV])) then "None" else [EV],
Replacer.ReplaceText,
{"EV"}
)
If this doesn't work as-is, then try changing Replacer.ReplaceText for Replacer.ReplaceValue.
Pete
Proud to be a Datanaut!