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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
neelofarshama
Post Partisan
Post Partisan

CONTAINS_TEXT DAX for calculated column

Hi all,

 

I have a column named "offer" which has data as shown below

 

 offer.PNG

I have to create a new column using DAX with the below case statement

case
when CONTAINS_TEXT(Offer,'08W001.00') then '8 Weeks | $1.00'
when CONTAINS_TEXT(Offer,'04W004.00') then '4 Weeks | $4.00'
when CONTAINS_TEXT(Offer,'04W001.00') then '4 Weeks | $1.00'
when CONTAINS_TEXT(Offer,'04W000.99') then '4 Weeks | $0.99'
when CONTAINS_TEXT(Offer,'13W001.00') then '13 Weeks | $1.00'
when CONTAINS_TEXT(Offer,'13W000.00') then '13 Weeks | $0.00'
when CONTAINS_TEXT(Offer,'08W007.92') then '8 Weeks | $7.92'
when CONTAINS_TEXT(Offer,'26W006.50') then '26 Weeks | $6.50'
when CONTAINS_TEXT(Offer,'52W000.00') then '52 Weeks | $0.00'
when CONTAINS_TEXT(Offer,'03Y000.00') then '3 Years | $0.00'
when CONTAINS_TEXT(Offer,'01W000.00') then '1 Week | $0.00'
when CONTAINS_TEXT(Offer,'26W000.00') then '26 Weeks | $0.00'
when CONTAINS_TEXT(Offer,'52W098.00') then '52Weeks | $98.00'
else Offer end.

 

Any help is highly appreciated.

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @neelofarshama 

 

You may try the following calculated column. 

Result = 
SWITCH(
    TRUE(),
    CONTAINSSTRINGEXACT('Table'[offer],"08W001.00"),"8 Weeks | $1.00",
    CONTAINSSTRINGEXACT('Table'[offer],"04W004.00"),"4 Weeks | $4.00",
    CONTAINSSTRINGEXACT('Table'[offer],"04W001.00"),"4 Weeks | $1.00",
    CONTAINSSTRINGEXACT('Table'[offer],"04W000.99"),"4 Weeks | $0.99",
    CONTAINSSTRINGEXACT('Table'[offer],"13W001.00"),"13 Weeks | $1.00",
    CONTAINSSTRINGEXACT('Table'[offer],"13W000.00"),"13 Weeks | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"08W007.92"),"8 Weeks | $7.92",
    CONTAINSSTRINGEXACT('Table'[offer],"26W006.50"),"26 Weeks | $6.50",
    CONTAINSSTRINGEXACT('Table'[offer],"52W000.00"),"52 Weeks | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"03Y000.00"),"3 Years | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"01W000.00"),"1 Week | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"26W000.00"),"26 Weeks | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"52W098.00"),"52Weeks | $98.00",
    "end"
)

 

From your smaple data, all records contains '08W001.00'. So the result is as below.

e1.png

 

Best Regards

Allan

 

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

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @neelofarshama 

 

You may try the following calculated column. 

Result = 
SWITCH(
    TRUE(),
    CONTAINSSTRINGEXACT('Table'[offer],"08W001.00"),"8 Weeks | $1.00",
    CONTAINSSTRINGEXACT('Table'[offer],"04W004.00"),"4 Weeks | $4.00",
    CONTAINSSTRINGEXACT('Table'[offer],"04W001.00"),"4 Weeks | $1.00",
    CONTAINSSTRINGEXACT('Table'[offer],"04W000.99"),"4 Weeks | $0.99",
    CONTAINSSTRINGEXACT('Table'[offer],"13W001.00"),"13 Weeks | $1.00",
    CONTAINSSTRINGEXACT('Table'[offer],"13W000.00"),"13 Weeks | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"08W007.92"),"8 Weeks | $7.92",
    CONTAINSSTRINGEXACT('Table'[offer],"26W006.50"),"26 Weeks | $6.50",
    CONTAINSSTRINGEXACT('Table'[offer],"52W000.00"),"52 Weeks | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"03Y000.00"),"3 Years | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"01W000.00"),"1 Week | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"26W000.00"),"26 Weeks | $0.00",
    CONTAINSSTRINGEXACT('Table'[offer],"52W098.00"),"52Weeks | $98.00",
    "end"
)

 

From your smaple data, all records contains '08W001.00'. So the result is as below.

e1.png

 

Best Regards

Allan

 

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

Hi Allan,

 

Thanks for the help, this is working now, but all other rows in the column are returning blank values which I dont want.

I want the other values to display as it is in the new calculated column.

Below is the screenshot for reference.

new.PNG

I found the solutions thanks anyway 

Thank you so much this worked.

Greg_Deckler
Super User
Super User

SWITCH(TRUE(),
SEARCH("08W001.00",[Offer]),"8 Weeks | $1.00",
SEARCH("08W004.00",[Offer]),"4 Weeks | $4.00",
...
)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi,

Thank you for the reply I have tried your solution but facing the below issue. 

switch error.PNG

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.