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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Dane
Helper I
Helper I

If Text Contains Statement

I have 2 related tables (one showing tracking history at different work cells and the other showing order details). I am trying to create a column in my Tracking History table that will calculate Linear Inches using the following logic:

 

If OrderDetails[PartNumber] contains "2L" then TrackingHistory[Width]*2 else (TrackingHistory[Width]*2) + (TrackingHistory[Height]*2)

 

Any recommendations?

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @Dane ,

 

Does this one here work for you?

IF (
    SEARCH ( 
        "2L",
        OrderDetails[PartNumber],
        1,
        BLANK()
    ),
    TrackingHistory[Width] *2,
    ( TrackingHistory[Width] *2 ) + ( TrackingHistory[Height] *2 )
)


I pressumed that your logical test shall search for "2L" in PartNumber, meaning "2L" could come up at different positions in a string (i.e. "ABC 2L", "2L DEF", "GHI 2L JKL" etc.). 

 

Let me know if this helps and if not, feel free to share some sample data and I can take a deeper look into it 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

10 REPLIES 10
Dane
Helper I
Helper I

Sorry it took me a couple of days to follow up. I was in a conference late last week. Attached is the link to the sharepoint site that has this file.

 

https://dreamwalls.sharepoint.com/sites/PowerBI/Shared%20Documents/Forms/AllItems.aspx

Hi,

That takes me to a sign-in page.  Please upload the file to Google Drive/One Drive and share the download link of that file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Below is the download link in google drive, please let me know if you have trouble accessing this. Thanks!

 

https://drive.google.com/file/d/1cIU1YZwPzxCC7vM1w1gDMYrGVVngQIIv/view?usp=sharing

Since you have not shared the sourcee Excel file, I cannot see your table in the queru Editor and there cannot provide a M language solution.  However, this calculated column formula works

Column = if(CONTAINSSTRING(OrderDetail[PartNo],"2L"),OrderDetail[Width]*2,(OrderDetail[Width]*2)+(OrderDetail[Height]*2))
Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

Try this formula in the Query Editor

=if Text.Contains(OrderDetails[PartNumber], "2L", Comparer.OrdinalIgnoreCase) then TrackingHistory[Width]*2 else (TrackingHistory[Width]*2) + (TrackingHistory[Height]*2)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I tried the formula you suggested and am getting an error in the column, the bottom of the page says "Expression.Error: We cannot convert a value of type list to type text.

Details:

Value=[List]

Type=[Type]

 

Dane_0-1654176962159.png

 

 

Share the download link of your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
tackytechtom
Super User
Super User

Hi @Dane ,

 

Does this one here work for you?

IF (
    SEARCH ( 
        "2L",
        OrderDetails[PartNumber],
        1,
        BLANK()
    ),
    TrackingHistory[Width] *2,
    ( TrackingHistory[Width] *2 ) + ( TrackingHistory[Height] *2 )
)


I pressumed that your logical test shall search for "2L" in PartNumber, meaning "2L" could come up at different positions in a string (i.e. "ABC 2L", "2L DEF", "GHI 2L JKL" etc.). 

 

Let me know if this helps and if not, feel free to share some sample data and I can take a deeper look into it 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I tried your solution but could not bring in OrderDetails[PartNo] into the formula for some inexplicable reason. Can I email you the PBIX I have?

Hi Dane,

 

I'd suggest that you upload your pbix file to a sharepoint or public dropbox folder and paste the link into the forum. With that others will be able to help you, too!

 

Alternatively, you could just paste a few rows of your two tables OrderDetails and TrackingHistory. Make sure to explain their connection as well 

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.