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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

More than 2 IF conditions to identify different data types in a mixed column not working- PowerQuery

I am trying to Add a new Column that uses multiple If conditions to check if a particular column contains a specific text, numbers formatted as text or textual values. The below If conditon works only for the first 2 criteria but adding a 3rd checking criteria does not yield the desired NULL results for numeric values that are formatted as text.

 

ColumnToCheckNewColumn
R0Questions
Is this my life?Is this my life?
0.5445null
0.23null
0.23335null

 

The formula is:

= Table.AddColumn(PreviousStep, "NewColumn",
each
if
Value.Is([ColumnToCheck],Text.Type) and not Text.Contains([ColumnToCheck],"R0") then
[ColumnToCheck]
else if
Text.Contains([ColumnToCheck],"R0", Comparer.OrdinalIgnoreCase) then
"Questions"
else if
Value.Is(Number.FromText([ColumnToCheck]),type number) then
null
else
null)

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, you may try what is suggested by @PhilipTreacy . I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

e1.png

 

You may add a new step with the following m codes.

= Table.AddColumn(#"Changed Type", "Custom", each try 
if Value.Is(Number.FromText([ColumnToCheck]),type number) then null 
else null
otherwise 
if Value.Is([ColumnToCheck],type text)
then
if Text.Contains([ColumnToCheck],"R0",Comparer.OrdinalIgnoreCase) 
then "Questions"
else [ColumnToCheck]
else null)

 

Result:

e2.png

 

Best Regards

Allan

 

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

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, you may try what is suggested by @PhilipTreacy . I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

e1.png

 

You may add a new step with the following m codes.

= Table.AddColumn(#"Changed Type", "Custom", each try 
if Value.Is(Number.FromText([ColumnToCheck]),type number) then null 
else null
otherwise 
if Value.Is([ColumnToCheck],type text)
then
if Text.Contains([ColumnToCheck],"R0",Comparer.OrdinalIgnoreCase) 
then "Questions"
else [ColumnToCheck]
else null)

 

Result:

e2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

PhilipTreacy
Super User
Super User

Hi @Anonymous 

This works

 

ThisStep = Table.AddColumn(PreviousStep, "Custom", 
    
        each try if Value.Is(Number.FromText([ColumnToCheck]), type number) then null else null
             otherwise if [ColumnToCheck] = "R0" then "Questions" else [ColumnToCheck] 
)

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


artemus
Microsoft Employee
Microsoft Employee

I think what you want is:

try Number.ToText([ColumnToCheck]) otherwise null

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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 Kudoed Authors