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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Mic1979
Post Partisan
Post Partisan

How to nest If in Functions

Dear all,

 

I found a very interesting video about  replacement values in a table.

Formula E | Electrified, Hankook iON x Formula E Technology (30s) | HankookTire

Probably most of you already saw this, but I thought it was good to share.

I have implemented it in my table:

 

A = Table.ToColumns (#"Removed Columns2"),
B = Table.ToRows (ReplacementTable_Body_StuffingBox1),

C = Table.FromColumns (List.Transform (
     A,
     each List.ReplaceMatchingItems (
     _,
     B,
     Comparer.OrdinalIgnoreCase
          )
     ),
     Table.ColumnNames (#"Removed Columns2")
)

 

It works.

However, I need to use this only if a special condition is verified.

Could you suggest how to include the if...then...else here?

 

In general, I have always problems when I need to add the if in the functions.

 

Thanks a lot for your help in advance.

5 REPLIES 5
v-sdhruv
Community Support
Community Support

Hi @Mic1979 

Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please Accept it as a solution  so other members can easily find it.
Thank You

v-sdhruv
Community Support
Community Support

Hi @Mic1979 

Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank You

v-sdhruv
Community Support
Community Support

Hi @Mic1979 

You are quite close-
You need to use nested if...else inside List.Transform and  make sure if is inside each  (i.e., per column list), not outside it. You can modify the syntax to something like this-

A = Table.ToColumns(#"Removed Columns2"),
B = Table.ToRows(ReplacementTable_Body_StuffingBox1),

C = Table.FromColumns(
List.Transform(
A,
each
if condition1 then
List.ReplaceMatchingItems(_, B, Comparer.OrdinalIgnoreCase)
else if condition2 then
List.ReplaceMatchingItems(_, B, Comparer.Ordinal)
else
_
),
Table.ColumnNames(#"Removed Columns2")
)
Hope this helps!

FreemanZ
Super User
Super User
grognard
Frequent Visitor

Hello

I think this is what you are looking for:

  A = Table.ToColumns (#"Removed Columns2"),
    B = Table.ToRows (ReplacementTable_Body_StuffingBox1),
    
    C = Table.FromColumns( 
    List.Transform(
        A, 
        each if condition then List.ReplaceMatchingItems(_,B,Comparer.OrdinalIgnoreCase) 
        else _
        ),
        Table.ColumnNames(#"Removed Columns2")
    )

just replace the 'condition' with the actual condition you are looking for and you should be good.

You can also nest if functions by chaining them together like so:

A = Table.ToColumns (#"Removed Columns2"),
    B = Table.ToRows (ReplacementTable_Body_StuffingBox1),
    
    C = Table.FromColumns( 
    List.Transform(
        A, 
        each
        //remember that the first condition that evaluates to true will result in the function returning.
        if condition1 then List.ReplaceMatchingItems(_,B,Comparer.OrdinalIgnoreCase) else
        if condition2 then List.ReplaceMatchingItems(_,B,Comparer.Ordinal)
        else _
        ),
        Table.ColumnNames(#"Removed Columns2")
    )

hope this helps 🙂

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors