cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ZELLAOUI Frequent Visitor
Frequent Visitor

DAX : If a column contains a certain value then a column contains this value.

Hello BI Community ! 

 

I have a column that contains a title. 

This title consists of "keywords" between brackets.

These first work between brackets refers to a "Category".

 

How can I have a column named "Category" that extract the keyword between bracket in my title ? 

Example : 

SSPowerBI.JPG

What I want, is to put a condition that looks like : 

 

If I have a [ALL] in my title, I want to put in my category to have [All]

If I have a [Stocks] in my title, I want to put in my category to have [Stocks].

 

Can anyone help me please ?

Many thanks ! 

 

Zakaria

 

1 ACCEPTED SOLUTION

Accepted Solutions
ZELLAOUI Frequent Visitor
Frequent Visitor

Re: DAX : If a column contains a certain value then a column contains this value.

Found the solution here : http://stackoverflow.com/questions/18059607/search-for-distinct-word-dax-formula

 

Here's the DAX code : 

Column = IF(IFERROR(SEARCH("[ALL]";'Backlog Live SM9'[Title]);-1)<> -1;"ALL"; IF(IFERROR(SEARCH("[Stocks]";'Backlog Live SM9'[Title]);-1)<> -1;"Stocks"; IF(IFERROR(SEARCH("[Opti]";'Backlog Live SM9'[Title]);-1)<> -1;"Opti" )))

 

View solution in original post

4 REPLIES 4
ZELLAOUI Frequent Visitor
Frequent Visitor

Re: DAX : If a column contains a certain value then a column contains this value.

Anyone ? Please ? Smiley Sad

ZELLAOUI Frequent Visitor
Frequent Visitor

Re: DAX : If a column contains a certain value then a column contains this value.

Found the solution here : http://stackoverflow.com/questions/18059607/search-for-distinct-word-dax-formula

 

Here's the DAX code : 

Column = IF(IFERROR(SEARCH("[ALL]";'Backlog Live SM9'[Title]);-1)<> -1;"ALL"; IF(IFERROR(SEARCH("[Stocks]";'Backlog Live SM9'[Title]);-1)<> -1;"Stocks"; IF(IFERROR(SEARCH("[Opti]";'Backlog Live SM9'[Title]);-1)<> -1;"Opti" )))

 

View solution in original post

sdjensen Senior Member
Senior Member

Re: DAX : If a column contains a certain value then a column contains this value.

If you want to solve this in the Query Editor using M instead of using DAX (personally I like to keep all transformation in Query Editor) it can be done by adding this step as the last step in the advanced editor.

 

#"Add Category" = Table.AddColumn(#"Name of previous step", "Category", 
        each if Text.PositionOf([Title], "]", Occurrence.First) = -1 
                then "" 
                else Text.Start( [Title], Text.PositionOf([Title], "]", Occurrence.First) +1 )
        )
in
    #"Add Category"

 

I created a small example:

TextFromOtherColumn.png

/sdjensen
melina Member
Member

Re: DAX : If a column contains a certain value then a column contains this value.

Hi All,

 

My question similar like this, but i involving around 30 of keywords.My keywords is factory. 

If F01, column category equals to F01,

IF F02, column category equals to F02,

.

.

.

IF F30,column cateogry equals to F30.

The problem is i have to write so many condition, It is there any simplest way?

 

Thanks!

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors