* Text Scheme Expression for Occupation

Questions regarding use of any Version of Family Historian. Please ensure you have set your Version of Family Historian in your Profile. If your question fits in one of these subject-specific sub-forums, please ask it there.
Post Reply
User avatar
sbell95
Famous
Posts: 107
Joined: 14 Feb 2021 06:04
Family Historian: V7
Location: Australia

Text Scheme Expression for Occupation

Post by sbell95 » 24 Mar 2023 03:22

Hi all,

I am wanting to include the first (or preferred) occupation of an individual on a diagram using my custom text scheme. However, in instances where an individual's first occupation is that of "Scholar" (ie, because of censuses), I want the text scheme to show either the next occupation that is not "Scholar" or my fact-flagged preferred occupation. Or perhaps a blank "No Occupation" in the case of there being no subsequent occupation facts.

I tried to implement the following expression in my text scheme, but it doesn't seem to work...

Code: Select all

=CombineText("(",ItemIf(%INDI.OCCU[1]% = "Scholar",ForceText("(No Occupation)"),%INDI.OCCU[preferred]%),")","")
Can anyone advise?

Sarah
Sarah Bell – Australia
View my tree on Wikitree

User avatar
tatewise
Megastar
Posts: 27078
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Text Scheme Expression for Occupation

Post by tatewise » 24 Mar 2023 11:08

When you say it doesn't seem to work it would help to explain what does not work.
Does it display nothing, display the wrong Occupation, display the expression, or what?

Let us investigate the expression components.

ItemIf( %INDI.OCCU[1]% = "Scholar", ForceText("(No Occupation)"), %INDI.OCCU[preferred]% )
ItemIf(...) is inappropriate as the parameters display text, so TextIf(...) is required.
ForceText(...) is redundant in this context as it is not governed by a subsequent data reference.
So we get:
TextIf( %INDI.OCCU[1]% = "Scholar", "(No Occupation)", %INDI.OCCU[preferred]% )
If the 1st Occupation is "Scholar" then that function displays "(No Occupation)" otherwise it displays the preferred Occupation or the 1st Occupation or nothing if neither of those exists.
So that does not match what your description specifies.

The =CombineText( "(", ... , ")", "" ) function surrounds the TextIf(...) display with brackets except when it is nothing.
So you get for example:
((No Occupation)) I don't think you really want double brackets?
(teacher)

I suggest you start with the =TextIf(...) function on its own in the Text Scheme and try to get nearer to your specification rather than me simply providing the solution. Remember to use the Test button in the Edit Text Scheme Item dialogue to check the syntax is valid.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
sbell95
Famous
Posts: 107
Joined: 14 Feb 2021 06:04
Family Historian: V7
Location: Australia

Re: Text Scheme Expression for Occupation

Post by sbell95 » 24 Mar 2023 12:08

Thank you, Mike. I think I've wrapped my head around it now -- I was overthinking the use of the =CombineText function.

My solution is now simply:

Code: Select all

(=TextIf(%INDI.OCCU% = "Scholar",%INDI.OCCU[2]%,%INDI.OCCU[preferred]%))
I also have an alt. text scheme item which just outputs "(No Occupation)" if the previous item is blank -- but I am unsure if the two items could be combined?

As an aside, the index [1] seems to get deleted from the first %INDI.OCCU% when I close/reopen the text scheme editor dialog -- is that the intended behaviour?

An example screenshot of my diagram with the above applied, in case anyone is interested:
Screenshot 2023-03-24 230529.png
Screenshot 2023-03-24 230529.png (205.25 KiB) Viewed 751 times
Sarah Bell – Australia
View my tree on Wikitree

User avatar
tatewise
Megastar
Posts: 27078
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Text Scheme Expression for Occupation

Post by tatewise » 24 Mar 2023 12:56

Yes, that is much nearer your stated requirement.

You don't need another Text Scheme Item, just use the 'No Data' Text: tick box and enter (No Occupation) there in the same item as your Template expression.

The index [1] is optional in any data reference as that is the default if no index is supplied and some Templates remove the [1] index to save space.

There is one case where your current expression may not perfectly match your stated requirement.
If the 1st Occupation is 'Scholar' it displays the 2nd Occupation even if the 3rd or later Occupation is Preferred.
You may need nested TextIf(...) functions to resolve that case.

BTW: Do you need to cope with both 'Scholar' and 'scholar' or any other case variant?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
tatewise
Megastar
Posts: 27078
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Text Scheme Expression for Occupation

Post by tatewise » 24 Mar 2023 14:05

I think this is the full expression you need and rather simpler than I anticipated:

Code: Select all

(=TextIf( ToLower(%INDI.OCCU[preferred]%) = "scholar", %INDI.OCCU[2]%, %INDI.OCCU[preferred]%))
i.e.
If no Occupation is preferred then the condition is testing %INDI.OCCU[1]% which is just like your original expression.
If an Occupation is preferred then presumably it will never be Scholar so %INDI.OCCU[preferred]% is always displayed.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
sbell95
Famous
Posts: 107
Joined: 14 Feb 2021 06:04
Family Historian: V7
Location: Australia

Re: Text Scheme Expression for Occupation

Post by sbell95 » 25 Mar 2023 00:12

You don't need another Text Scheme Item, just use the 'No Data' Text: tick box and enter (No Occupation) there in the same item as your Template expression.
Of course! So obvious once you mentioned it.
BTW: Do you need to cope with both 'Scholar' and 'scholar' or any other case variant?
I use consistent occupation titles, so all of them will be "Scholar".

Code: Select all

(=TextIf( ToLower(%INDI.OCCU[preferred]%) = "scholar", %INDI.OCCU[2]%, %INDI.OCCU[preferred]%))
What role does the ToLower function play here? And I'm guessing the first parameter uses %INDI.OCCU[preferred]% because FH takes the first occupation fact as preferred (unless otherwise set by a fact flag) -- is that right?
Sarah Bell – Australia
View my tree on Wikitree

User avatar
laz_gen
Famous
Posts: 150
Joined: 03 Apr 2018 14:02
Family Historian: V7
Contact:

Re: Text Scheme Expression for Occupation

Post by laz_gen » 25 Mar 2023 08:57

BTW: Do you need to cope with both 'Scholar' and 'scholar' or any other case variant?
I think it is meant to cope with different uses of upper case so a comparison of Scholar to scholar doesn't fail.

It converts all text found in the OCCU fact to lower case before doing its comparison looking for scholar.

User avatar
tatewise
Megastar
Posts: 27078
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Text Scheme Expression for Occupation

Post by tatewise » 25 Mar 2023 10:29

The purpose of the ToLower(...) function is given in the FH Help for Functions pages. See ToLower page.
As laz-gen says, it converts the Occupation to lowercase text for comparison with "scholar" so it is case-independent.

Yes, if there is no Preferred Occupation then the 1st Occupation is used.
See Understanding Data References under Advanced Indices where it says:
It is possible to set a flag on events and attributes to indicate that a fact is a preferred fact. For example, you may have recorded numerous occupations for a given person, but one of them may be the occupation that they were most closely associated with; and you may choose to mark this occupation as the preferred one, by setting the Preferred flag for that fact. You can reference a preferred fact by using [preferred] as the index. e.g.:

%INDI.OCCU[preferred]%

If a given person has no occupation which has the Preferred flag set, this will return the first one.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
sbell95
Famous
Posts: 107
Joined: 14 Feb 2021 06:04
Family Historian: V7
Location: Australia

Re: Text Scheme Expression for Occupation

Post by sbell95 » 25 Mar 2023 23:42

I know what the funcion does; I was just wondering why it was required here. Both you and laz_gen have now answered that, so thank you.

If I am consistent throughout my project in recording the occupation as "Scholar" (rather than "scholar" or "sChOlar"), can my text scheme expression simply be closer to what I originally suggested?

Code: Select all

(=TextIf(%INDI.OCCU[preferred]%) = "Scholar", %INDI.OCCU[2]%, %INDI.OCCU[preferred]%)
Sarah Bell – Australia
View my tree on Wikitree

User avatar
tatewise
Megastar
Posts: 27078
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Text Scheme Expression for Occupation

Post by tatewise » 26 Mar 2023 10:21

Yes, but you have not got all the closing brackets ) in the correct positions.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply