Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Help with creating Formula Field to extract parts Post Reply Post New Topic
Author Message
ShaunS614
Newbie
Newbie


Joined: 12 May 2014
Location: United States
Online Status: Offline
Posts: 2
Quote ShaunS614 Replybullet Topic: Help with creating Formula Field to extract parts
     Posted: 12 May 2014 at 8:21am
I am not sure anyone can help with this but any help would be SO appreciated!


I am unsure how to create a formula within the report I am writing to accomplish something in particular requested by management at my workplace for one of their own purposes,
and would love your help to get this working if you have knowledge of this concept and be most thankful

the field name I am working with is
{Inventory_Items.Host Name}

I have been asked to create a formula that will produce some of the Host Name String.

For example, we have some host names that have a dash in them , for example the host name is
Merlin-Test

Some of the host names do not have a dash
Merlin

I have a need to create one formula that will capture everything left of the dash (if there is a dash)
Then I need a formula to capture everything right of the dash (if there is a dash)
else just the host name

So in this idea, I don't know if I need some form of an "if then else" statement or three formulas?

So lets say in my above example with Merlin and Merlin-Test and a third hostname called IONA

I need to have a formula field that will show on the report the following visual:


Lets say we call the formula field for everything left of the dash "Top Level Host Name"

So this would produce the result of Merlin when it evaluates that we have Merlin-Test

A second column called "Second Level" would produce the word
Test
because test is right of the - in "merlin-test" host name

And then a third column hypotetically called Host no Dash
would produce the result of

Iona

Because Iona is listed in this field with no dashes in the host name


So if the hostname list in the database comprised of
Merlin
Merlin-Test
Iona


Then the result report would show

"Top Level Host Name"
Merlin

"Second Level"
Test

"Host no Dash"
Iona


Conceptually what I am trying to do is have a report that evaluates the host name field and if it find
the host name has a dash in it then I need one column that will show left of... a column that shows right of dash
and a third column that only captures host names with no dash
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 May 2014 at 10:28am
you will need 3 formual fields to display in your 3 columns
Top
if instr({field},"-")>0 then split({field},"-") [1] else ""
 
Second
if instr({field},"-")>0 then split({field},"-") [2] else ""
 
no dash
if instr({field},"-")=0 then {field} else ""
 
EDIT: not sure if that is will work as I am not sure what the difference is between "Merlin" and "Iona"...


Edited by DBlank - 12 May 2014 at 10:30am
IP IP Logged
ShaunS614
Newbie
Newbie


Joined: 12 May 2014
Location: United States
Online Status: Offline
Posts: 2
Quote ShaunS614 Replybullet Posted: 13 May 2014 at 1:53am
These formulas seem to work and now I can tweak them from here! thank you so much for your assistance!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum