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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ldwf
Helper IV
Helper IV

Report Builder MID Function not defaulting to 'N/A'

I am using a combination of INSTR and MID functions to search a text field for a specific value and if the value is found, I return everything after this text until a period is found. If the specific value is not found, I want to return "N/A" but instead get a value of #Error. If the value is found, it is correctly displayed but I can't get the 'N/A' to appear; it always returns #Error. I define two fields using INSTR function; one to show the first position that the value is found, and the second to show the position the period is in and use the values in the MID function. I noticed that the INSTR function returns an integer value of 0 if the value isn't found, so I write my MID function to check if the value is 0 and return 'N/A' if it is; i.e, IIF(Fields!Starting_Position_of_Text.Value=0, "N/A", MID(Fields!Comments.Value, Fields!Starting_Position_of_Text.Value, (Fields!Location_of_Period_in_Text.Value-Fields!Starting_Position_of_Text.Value))). This works fine if the text value is there but otherwise it shows #Error instead of 'N/A'.

1 ACCEPTED SOLUTION

Hi,

This calculated column formula works.

Column = IFERROR(MID(Data[Text],SEARCH("Hello ",Data[Text]),SEARCH(".",Data[Text])-SEARCH("Hello ",Data[Text])),"N/A")

Hope this helps.

Ashish_Mathur_0-1734392242088.png

 

 


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

View solution in original post

5 REPLIES 5
PhilipTreacy
Super User
Super User

@ldwf 

 

If the substring is not found, so INSTR returns 0, what value is in Fields!Comments.Value ?

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


The value in Fields!Comments.Value is some text, but each record may not have the text that I need to extract.  So if for example I am searching each record for a text value of 'Hello World' and need to extract it, the function does work fine if the field contains 'Hello World', but if it contains some other text like 'Hello Everyone', it shows Error# and I want it to show 'N/A'.  My Instr function to search for the first position of 'Hello World' does return a value of 0 if it can't find this in the text, so this is why my IIF is written the way it is.

Ashish_Mathur
Super User
Super User

Hi,

If you want a calculated column or a Power Query solution, then share some data to work with and show the expected result.


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

Hi.  I am not permitted to upload any data.  I'll try to explain the problem more simple.  I have a text field and need to search for a value of 'Hello' in the text field and return this value and every character after it until a period is found.  So if the text says 'ABC Hello there.  WXYZ', I need to return 'Hello there'.  I use the Instr function to get the starting position, and another Instr function to get the position of where the period is.  I then have a field that uses the MID function to extract this text.  It works fine except when it can't find the text 'Hello'.  If the text field for any record doesn't have 'Hello', the function returns Error#.  I want it to return 'N/A'.   The INSTR function does assign a zero to the field called Starting_Position_of_Text if it can't find 'Hello', so I write my MID function as IIF(Fields!Starting_Position_of_Text.Value=0, "N/A", MID(Fields!Comments.Value, Fields!Starting_Position_of_Text.Value, (Fields!Location_of_Period_in_Text.Value-Fields!Starting_Position_of_Text.Value))).  But this always give me #Error instead of 'N/A'

Hi,

This calculated column formula works.

Column = IFERROR(MID(Data[Text],SEARCH("Hello ",Data[Text]),SEARCH(".",Data[Text])-SEARCH("Hello ",Data[Text])),"N/A")

Hope this helps.

Ashish_Mathur_0-1734392242088.png

 

 


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

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 MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.