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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.