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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
RobKay12
Helper I
Helper I

Looking for a specific formula

I am drawing a blank and I know if it is possible, that it is probably a easy answer. I have a table with over 1000 rows and each row has hundreds of columns. 

I want to add a forumla in the last column to say that if a specific word is found in that row then make that column a 1, otherwise leave it blank. 

I know how to do this if I point to each and every column but was wondering if there was a shorter formula.

Thank you for any assistance.

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @RobKay12 ,
if you add column with this formula, you will get a match for each substring:

if Text.Contains(Text.Combine(List.Transform(Record.FieldValues(_), (l)=> Text.From(l)),  " "), "myWord") then 1 else null

if you are only interested in full matches, you need to use this formula:

if List.Contains(Record.FieldValues(_), "myWord") then 1 else null

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

10 REPLIES 10
ImkeF
Community Champion
Community Champion

No worries 🙂
Just make sure to close your question over in the DAX-forum.
And please mark my solution as a solution, so this thread can be closed as well.
Thx!

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

Also, there is no concept in DAX for such a dynamic approach.
You would have to do it in Power Query using the M-language.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

Hi @RobKay12 ,
this is the forum section for Power Query (in the query editor).
You cannot use DAX Studio for it.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

Has been valid for me.
If you would post the error-message and your M-code we could make it work for you as well.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

RobKay12_0-1692986306056.png

 

ImkeF
Community Champion
Community Champion

Hi @RobKay12 ,
if you add column with this formula, you will get a match for each substring:

if Text.Contains(Text.Combine(List.Transform(Record.FieldValues(_), (l)=> Text.From(l)),  " "), "myWord") then 1 else null

if you are only interested in full matches, you need to use this formula:

if List.Contains(Record.FieldValues(_), "myWord") then 1 else null

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

My appologies. I posted the same question in the DAX section and was thinking i was there when replying to you. I just put the formula in the Query editor and ureka it works.

 

Thank you very much. I will pay closer attention going forward 🙂

Thanks for this. Seems to be invalid though.

ImkeF
Community Champion
Community Champion

Hello @RobKay12 ,
can that word be found as a substring anywhere in any cell/column or must it match the whole columns value?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

It would be a specific word. As long as it was found atleast once in any column of the row then I would like it to return a 1.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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