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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Nigel_Mayhew1
Helper I
Helper I

If a specific value/text exists in any of the columns then return a value/text

Hi there,

 

I need to look up a specific value/text in multiple columns at once, without having to list all the column names (the column names could change in the future). Then, if the value/text is found in any of the columns, I need to have the first 6 charachters of the contents of the cell.

 

Here is a basic example:

 

Column1Column2Column3Column4Column5Column6Column7Column8Column9Column10Column11Column12Result

Hello1ByeByeByeByeByeByeByeByeByeByeByeHello1
ByeByeHello956ByeByeByeByeByeByeByeByeByeHello9
ByeByeByeByeByeByeHello42ByeByeByeByeByeHello4
ByeByeByeByeByeByeByeByeByeHello1ByeByeHello1
ByeByeByeHello777ByeByeByeByeByeByeByeByeHello7
ByeByeByeByeByeByeByeByeByeByeHello55ByeHello5

 

Can someone help?

 

Many thanks,

Nigel

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Nigel_Mayhew1 ,

If you don't want list all the column names, then there is no way to achieve this by DAX or other function in Power BI Desktop. I'm afraid that you can only achieve this by Power Query.
First, you can use Ctrl + A to choose the whole table and Merge columns:

vjunyantmsft_0-1715047869961.png

vjunyantmsft_1-1715047900894.png

 

Then use this M function to add a custom column:

let
    TextToFind = "Hello",
    FoundIndex = Text.PositionOf([Merged], TextToFind, Occurrence.First)
    in
    if FoundIndex = -1 then null
    else Text.Middle([Merged], FoundIndex, 6)

vjunyantmsft_2-1715047932351.png


Then split the previously merged column:

vjunyantmsft_3-1715047997943.png

vjunyantmsft_4-1715048010884.png


Click "Close & Apply":

vjunyantmsft_5-1715048042655.png


And the final output is as below:

vjunyantmsft_6-1715048067958.png


Here is the whole M function in the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjNyck3VNJRcqpMpYiM1YlGEQMbbGlqRiXjcJFga0yMqGQaDvMNiTAMrNDc3JxmPsXrQlNTmGmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t, Column11 = _t, Column12 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", type text}}),
    #"Merged Columns" = Table.CombineColumns(#"Changed Type",{"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"),
    #"AddColumn" = Table.AddColumn(#"Merged Columns", "Custom Column", each let
    TextToFind = "Hello",
    FoundIndex = Text.PositionOf([Merged], TextToFind, Occurrence.First)
    in
    if FoundIndex = -1 then null
    else Text.Middle([Merged], FoundIndex, 6)),
    #"Split Column by Delimiter" = Table.SplitColumn(AddColumn, "Merged", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Merged.1", "Merged.2", "Merged.3", "Merged.4", "Merged.5", "Merged.6", "Merged.7", "Merged.8", "Merged.9", "Merged.10", "Merged.11", "Merged.12"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged.1", type text}, {"Merged.2", type text}, {"Merged.3", type text}, {"Merged.4", type text}, {"Merged.5", type text}, {"Merged.6", type text}, {"Merged.7", type text}, {"Merged.8", type text}, {"Merged.9", type text}, {"Merged.10", type text}, {"Merged.11", type text}, {"Merged.12", type text}})
in 
    #"Changed Type1"


Best Regards,
Dino Tao
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

1 REPLY 1
Anonymous
Not applicable

Hi @Nigel_Mayhew1 ,

If you don't want list all the column names, then there is no way to achieve this by DAX or other function in Power BI Desktop. I'm afraid that you can only achieve this by Power Query.
First, you can use Ctrl + A to choose the whole table and Merge columns:

vjunyantmsft_0-1715047869961.png

vjunyantmsft_1-1715047900894.png

 

Then use this M function to add a custom column:

let
    TextToFind = "Hello",
    FoundIndex = Text.PositionOf([Merged], TextToFind, Occurrence.First)
    in
    if FoundIndex = -1 then null
    else Text.Middle([Merged], FoundIndex, 6)

vjunyantmsft_2-1715047932351.png


Then split the previously merged column:

vjunyantmsft_3-1715047997943.png

vjunyantmsft_4-1715048010884.png


Click "Close & Apply":

vjunyantmsft_5-1715048042655.png


And the final output is as below:

vjunyantmsft_6-1715048067958.png


Here is the whole M function in the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjNyck3VNJRcqpMpYiM1YlGEQMbbGlqRiXjcJFga0yMqGQaDvMNiTAMrNDc3JxmPsXrQlNTmGmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t, Column11 = _t, Column12 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", type text}}),
    #"Merged Columns" = Table.CombineColumns(#"Changed Type",{"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"),
    #"AddColumn" = Table.AddColumn(#"Merged Columns", "Custom Column", each let
    TextToFind = "Hello",
    FoundIndex = Text.PositionOf([Merged], TextToFind, Occurrence.First)
    in
    if FoundIndex = -1 then null
    else Text.Middle([Merged], FoundIndex, 6)),
    #"Split Column by Delimiter" = Table.SplitColumn(AddColumn, "Merged", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Merged.1", "Merged.2", "Merged.3", "Merged.4", "Merged.5", "Merged.6", "Merged.7", "Merged.8", "Merged.9", "Merged.10", "Merged.11", "Merged.12"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged.1", type text}, {"Merged.2", type text}, {"Merged.3", type text}, {"Merged.4", type text}, {"Merged.5", type text}, {"Merged.6", type text}, {"Merged.7", type text}, {"Merged.8", type text}, {"Merged.9", type text}, {"Merged.10", type text}, {"Merged.11", type text}, {"Merged.12", type text}})
in 
    #"Changed Type1"


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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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