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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
ashraf999
Regular Visitor

Problem with Nested Power Query If Statement

Hello,

 

I am not sure where the mistake is in the following nested if statement. The query searches for a string in column3. Then it validates column5 and column6 to decide if the value of column4 is to be replaced.

 

 

Capture.JPG

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ashraf999 ,

 

Please try:

= Table.ReplaceValue(#"Changed Type",each [Column4],
	  each if Text.Contains([Column3],"Instant Payment BSF/MBK") then 
	  	      if (Value.Is(try Number.FromText([Column5]) otherwise null, type number)) then [Column5]
	  	      else if (Value.Is(Number.FromText([Column6]), type number)) then [Column6]
              else [Column4]			  
      else [Column4],Replacer.ReplaceValue,{"Column4"})

vcgaomsft_0-1676255917754.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
ams1
Responsive Resident
Responsive Resident

A915F6BA-0913-4E15-843D-E04A145399EE.jpeg

 I don't see the Else for the IF highlighted in the pic above.

 

Rule of thumb: nr of IFs should equal nr of ELSEs 😁

I tried your suggestion by using this code:

 

= Table.ReplaceValue(#"Changed Type",each [Column4],
	  each if Text.Contains([Column3],"Instant Payment BSF/MBK") then 
	  	      if (Value.Is(Number.FromText([Column5]), type number)) then [Column5] 
	  	      else if (Value.Is(Number.FromText([Column6]), type number)) then [Column6]
              else [Column4]			  
      else [Column4],Replacer.ReplaceValue,{"Column4"})

 

However, it is not giving the results I want. Here is a sample of the data. As you can see records 21 & 22 should be replaced by the values in Column6:

 

Capture2.JPG

 

 

Anonymous
Not applicable

Hi @ashraf999 ,

 

Please try:

= Table.ReplaceValue(#"Changed Type",each [Column4],
	  each if Text.Contains([Column3],"Instant Payment BSF/MBK") then 
	  	      if (Value.Is(try Number.FromText([Column5]) otherwise null, type number)) then [Column5]
	  	      else if (Value.Is(Number.FromText([Column6]), type number)) then [Column6]
              else [Column4]			  
      else [Column4],Replacer.ReplaceValue,{"Column4"})

vcgaomsft_0-1676255917754.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.