* How to create a query using Boolean logic

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
avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 12:19

Dear All,

How do I create a Query using Boolean logic?

I need to list all my ancestors that do have a "surname" but also ancestors whose father has a "surname".

At the end I will "eliminate people without surnames, whose father also has no surname....

I manage to create the following query:
But the two last conditions should work together as an AND. I need both to be true together.
Capturar.JPG
Capturar.JPG (17.01 KiB) Viewed 12301 times
Regards and Thanks a lot.
Family Historian Version 6

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

Re: How to create a query using Boolean logic

Post by tatewise » 07 Jul 2017 13:37

They are actually working together as an AND, and both must be true.

But I suspect you have overlooked the cases where there is no Father or no Father's Name at all, in which case the test for %...:SURNAME% matches '' fails because it is null.

So you need another Row filter for:
Exclude if %INDI.~FATH[1]>NAME[1]% is null
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Jane
Site Admin
Posts: 8442
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: How to create a query using Boolean logic

Post by Jane » 07 Jul 2017 14:10

You might find it easier to either reverse the logic or use the AND function, although I suspect you want to do
"Is Ancestor and (Indi:name:surname is not null or INDI.~FATH>NAME:SURNAME is not null

I think you want everyone with a Surname plus everyone whose Father has a Surname.

So I would

Add if INDI.NAME:SURNAME is not null
Add if INDI.~FATH>NAME:SURNAME is not null
exclude unless is Ancestor.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 14:19

Hi Tate,

Maybe I did not understood.
But when doing this the query it is eliminating more people than it should.

I tried this:
Capturar2.JPG
Capturar2.JPG (16.33 KiB) Viewed 12275 times
Doing like you said it is eliminating all people without surnames, but it should only eliminate people without surname, IF there is nos father...

Ex.

Marie Anne // has no father and should be eliminated.
Barbara // has a father named Karl /Langer/ and should not be eliminated.


Exclude if %INDI.~FATH[1]>NAME[1]% is null

This will eliminate all people with no father, even if they have a surname...
Family Historian Version 6

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 14:39

Hi Jane,

Reverse order, may work. You are right...

How do I add this "is not null"

I could not find it on the list...
Sem título.png
Sem título.png (6.09 KiB) Viewed 12271 times
Family Historian Version 6

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

Re: How to create a query using Boolean logic

Post by tatewise » 07 Jul 2017 14:45

What I actually said was to use your existing filters, and ADD the is null filter.
Reversing the order of your two Exclude if ... matches '' filters makes NO difference.

You also misunderstand how filters work.
They operate on the current Result Set not the whole database.
So for your filters the first one fills the Result Set with all Ancestors.
Exclude if %INDI.NAME[1]:SURNAME% matches '' excludes everyone with no Surname from the Result Set of Ancestors.
So now the Result Set holds only Ancestors who do have a Surname.
Exclude if %INDI.~FATH[1]>NAME[1]:SURNAME% matches '' excludes those whose Father exists with a Name but no Surname.
So now the Result Set holds only Ancestors who do have a Surname AND either no Father's Name, or no Father's Surname.
Exclude if %INDI.~FATH[1]>NAME[1] is null excludes from the Result Set those whose Father's Name does not exist.
So the Result Set ends with Ancestors who have a Surname AND whose Father also has a Surname.

BTW: You also may need to consider initial Ancestors who have no Name at all.
i.e. Exclude if %INDI.NAME[1] is null

However, your latest example seems to suggest you want the filters to OR together.
i.e. List Ancestors whose Surname exists OR whose Father's Surname exists.
Is that correct?

Instead of using Add if use Exclude if
i.e. Add if ... is not null is the same as Exclude if ... is null.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
LornaCraig
Megastar
Posts: 2996
Joined: 11 Jan 2005 17:36
Family Historian: V7
Location: Oxfordshire, UK

Re: How to create a query using Boolean logic

Post by LornaCraig » 07 Jul 2017 14:50

How do I add this "is not null"
You need to use Add Unless.... Is null
This is logically equivalent to Add if... not null.

(This is if you are using Jane's method, where you start with an empty set, and the last step is to Exclude unless an Ancestor.)
Lorna

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 15:22

Yes,

I am trying:

Ancestors whose Surname exists OR whose Father's Surname exists.
Family Historian Version 6

User avatar
LornaCraig
Megastar
Posts: 2996
Joined: 11 Jan 2005 17:36
Family Historian: V7
Location: Oxfordshire, UK

Re: How to create a query using Boolean logic

Post by LornaCraig » 07 Jul 2017 15:28

Add unless INDI.NAME:SURNAME is null
Add unless INDI.~FATH>NAME:SURNAME is null
Exclude unless Ancestor of .....
Lorna

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

Re: How to create a query using Boolean logic

Post by tatewise » 07 Jul 2017 16:00

Sorry Lorna but that does not work, because it includes people that exist with Names but without Surnames.
So the filters always need tests for NAME is null and for SURNAME matches ''
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 16:11

Hi

I am still not achieving the results.
I tried the following:
Capturar4.JPG
Capturar4.JPG (17.55 KiB) Viewed 12241 times
But I am getting many people as a result withou surnames, or whose father has no surname...

Am I missing something?

Pedro
PS. How do you copy the expressions? I am always using printscreen here... :-)
Family Historian Version 6

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 16:21

Almost there:
Capturar5.JPG
Capturar5.JPG (16.68 KiB) Viewed 12237 times
But when a person with no surnames has a father also with no surnames, they are listed...

Pedro
Family Historian Version 6

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

Re: How to create a query using Boolean logic

Post by tatewise » 07 Jul 2017 16:25

To copy the Expression part use the standard right-click Copy and Paste or the standard shortcuts Ctrl+C and Ctrl+V

I have resorted to a full boolean logic expression using the =IsTrue(...) function :-
Add if
=IsTrue((Exists(%INDI.NAME%) and Not(%INDI.NAME:SURNAME% = "")) or (Exists(%INDI.~FATH>NAME%) and Not(%INDI.~FATH>NAME:SURNAME% = "")))
is true

That must be followed by the usual :-
Exclude unless an ancestor...

OR you can do it the other way round :-
Add if an ancestor...
Exclude unless
=IsTrue((Exists(%INDI.NAME%) and Not(%INDI.NAME:SURNAME% = "")) or (Exists(%INDI.~FATH>NAME%) and Not(%INDI.~FATH>NAME:SURNAME% = "")))
is true
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
LornaCraig
Megastar
Posts: 2996
Joined: 11 Jan 2005 17:36
Family Historian: V7
Location: Oxfordshire, UK

Re: How to create a query using Boolean logic

Post by LornaCraig » 07 Jul 2017 16:35

tatewise wrote:Sorry Lorna but that does not work, because it includes people that exist with Names but without Surnames.
So the filters always need tests for NAME is null and for SURNAME matches ''
But Pedro has repeatedly said it is the existence of the surname he is interested in. I took this to mean that if someone has a name but no surname they should be treated in the same way as someone with no name at all. Perhaps Pedro will clarify this.

Pedro: Mike may well correct me but I believe the method I gave above using
Add unless INDI.NAME:SURNAME is null
Add unless INDI.~FATH>NAME:SURNAME is null
Exclude unless Ancestor of .....
will work. It will indeed produce a list of people with no surnames or whose father has no surname. You can then add these people to a named list. If you want to see all the other Ancestors, use another query which Adds all Ancestors and Excludes if a member of the named list.
Lorna

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 16:43

Hi Lorna,

your attempt is returning people with no surname, but that have no father at all (end of lines...)

It looks like if there is no father it ignores the second test....
Family Historian Version 6

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 16:50

Tate,

It looks lik it has worked!

Add if
=IsTrue((Exists(%INDI.NAME%) and Not(%INDI.NAME:SURNAME% = "")) or (Exists(%INDI.~FATH>NAME%) and Not(%INDI.~FATH>NAME:SURNAME% = "")))
is true
followed by the usual :-
Exclude unless an ancestor...

What I have not managed is to ctrl+c ctrl+v from the FH. :-)

Thanks a lot!!!
Family Historian Version 6

User avatar
LornaCraig
Megastar
Posts: 2996
Joined: 11 Jan 2005 17:36
Family Historian: V7
Location: Oxfordshire, UK

Re: How to create a query using Boolean logic

Post by LornaCraig » 07 Jul 2017 16:55

psinacio wrote: your attempt is returning people with no surname, but that have no father at all (end of lines...)
OK, just a misunderstanding. I had assumed that in cases where there was no father at all you would treat that the same as a father with no surname.
Lorna

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

Re: How to create a query using Boolean logic

Post by tatewise » 07 Jul 2017 17:08

Pedro, you cannot copy the entire filter, only the Expression component for each Row shown in the box at the bottom.

Lorna, try Add unless %INDI.NAME[1]:SURNAME% is null on its own and you will see the problem.
It simply omits records without a NAME field, but keeps those with a Given Name but no SURNAME.

The same problem affects Add unless %INDI.~FATH[1]>NAME[1]:SURNAME% is null
That omits non-existent Fathers and omits Fathers without a NAME field, but keeps Fathers without a SURNAME.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
psinacio
Diamond
Posts: 51
Joined: 11 Jun 2012 02:17
Family Historian: V6

Re: How to create a query using Boolean logic

Post by psinacio » 07 Jul 2017 17:19

Thanks Mike / Lorna and JAne,

This one was particular difficult to achieve!
Family Historian Version 6

Post Reply