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
sparvez
Helper I
Helper I

If a column contains its value in another column as string

Hello ,

I am trying to do this.  If  A1 column value exist in A2 column as string then, give me result in 'A2_evolution' column as the value of A1. If no, then just keep A2 as it is.  

Can anyone help pls ?  Thanks in advance.

 

A1A2 A2_evolution
banana apple1212213 apple
orange orangesdfsdf orange
avocado  banana3453453 banana
apple avocado34234SFSFSDF avocado
 pear343434 pear343434
1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @sparvez,

 

Give this a go.

let
    lookFor = List.Buffer( Source[A1]),
    Source = Table.FromColumns(
        {
            {"banana", "orange", "apple" },
            { "apple15468", "pearpaihga", "banana0294576" }
        }, type table[ A1 = text, A2 = text]
    ),
    AddCol = Table.AddColumn(Source, "A2_evolution", each List.First( 
        List.Select( lookFor, (x)=> x = Text.Start( [A2], Text.Length(x) ))
        ) ?? [A2], type text 
    )
in
    AddCol

 

with this result.

m_dekorte_0-1686342359830.png

 

Ps. If this helps you solve your query, please mark it as solution. Thanks!

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @sparvez ,

 

You can add a A1 list and then expand it for comparing.

vstephenmsft_0-1687424916249.png

Add a custom column to compare.

vstephenmsft_1-1687424962924.png

vstephenmsft_2-1687424969248.png

 

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

 

 

sparvez
Helper I
Helper I

Hi m dekorte

thanks, but the columns have thousand of value. I cannot write the data itself into code. Do you see a way where I can just indicate columln name ?

            {"banana", "orange", "apple" },
            { "apple15468", "pearpaihga", "banana0294576" }

  Thanks again for your time

Hi @sparvez

 

You don't have to write a list by hand. Examine the lookFor variable, it returns a list by referencing tableName[columnName]

The User Interface can create the syntax for you, just right click the column header and select drill down. That will add a step to your query, you can copy the code from the formula bar to use it elsewhere and delete that step once you're done. 

HI,

Can u pls post the entire code pls ?

Hi @sparvez ,

The full code was shared in the initial response, you can copy it  all into a new blank query

Hi, the proposed table is just a sample. The originale file , i have over 10 thousand rows.  So, a generic solution would be nice pls.

The only values that are hard coded are used to build the Source table.

Used column reference to create the lookFor list with values:

    lookFor = List.Buffer( Source[A1])

 

and referenced that in the AddCol step

 

What's not generic about this solution, in your view?

m_dekorte
Super User
Super User

Hi @sparvez,

 

Give this a go.

let
    lookFor = List.Buffer( Source[A1]),
    Source = Table.FromColumns(
        {
            {"banana", "orange", "apple" },
            { "apple15468", "pearpaihga", "banana0294576" }
        }, type table[ A1 = text, A2 = text]
    ),
    AddCol = Table.AddColumn(Source, "A2_evolution", each List.First( 
        List.Select( lookFor, (x)=> x = Text.Start( [A2], Text.Length(x) ))
        ) ?? [A2], type text 
    )
in
    AddCol

 

with this result.

m_dekorte_0-1686342359830.png

 

Ps. If this helps you solve your query, please mark it as solution. Thanks!

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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