Answers.Body: <p>You could do it in two steps:</p>
  <ol>
  <li>One SK to create a smart group of contacts who have made donations
  eg &quot;Contributors&quot;</li>
  <li>One SK to create a listing grouped by age bracket,
  with a filter condition of &quot;In groups&quot; &quot;Contributors&quot;</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-31T19:42:25.100Z
Answers.Text: Can searchkit use smart groups?
Answers.UserDisplayName: themak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-01T13:59:50.697Z
Answers.Text: @themak yes - there's a WHERE filter for Contacts (which is confusing because it seems like you should join Contacts to Groups, but that won't catch smart groups).
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-31T10:24:23.210Z
Answers.LastActivityDate: 2024-10-31T10:24:23.210Z
Answers.UserDisplayName: Aidan
Answers.Body: <p>Aidan's solution is workable here, because you aren't, e.g., asking for the totals of donations by age group. But if you did, there's a more advanced technique.</p>
  <p>You can use SearchKit results in a second SearchKit query. You can do that by creating a display of type &quot;Entity&quot;.  So if, e.g., you needed total amounts by age group:</p>
  <ul>
  <li><p>You'd make one search of contacts joined to contributions, with total amounts, grouped by contact, then save it as an entity.</p>
  </li>
  <li><p>Then you could make a second query where you take contacts and join to the results of query 1. Then you group by age group.</p>
  </li>
  </ul>
  <p>By pre-grouping in query 1, you take what would ordinarily be a &quot;one-to-many&quot; join (contacts to contributions) and turn it into a &quot;one-to-one&quot; join. That prevents any duplication of rows to throw off your numbers.</p>
  <p>This is actually the most common application of the Entity display - you need to group by two criteria without duplicate rows throwing off your results.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-01T15:03:23.980Z
Answers.LastActivityDate: 2024-11-01T15:03:23.980Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>SearchKit might seem strange at first if you are not familiar with the basics of SQL. You might be interested to read over an intro to SQL to understand how joins work. Basically, when you join one table to another, SQL will return a row for every matching join. You can find lots of illustrations out there to help you with the concept, like this one, which shows that a contact with multiple contributions will return multiple rows:</p>
  <p><a href="https://i.sstatic.net/lQEh8A39.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lQEh8A39.png" alt="SQL Join" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-30T15:24:04.807Z
Answers.Text: 1) Is there a way the Search search results return only unique contact ids (i.e. contacts rather than contributions) in such search? 2) This SQLish behavior also means wrong sums of Contact IDs (not sum of unique, but of every duplicate) and money when counting all together.
Answers.UserDisplayName: Aivars
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-30T23:10:19.313Z
Answers.Text: that second blue line on the right is confusing me!
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-31T10:25:42.280Z
Answers.Text: @petednz-fuzion - note the top section is two separate tables.
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-01T18:27:22.447Z
Answers.Text: LOL. no i hadn't picked that up, just read left col and hten right col
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-01T19:05:39.623Z
Answers.Text: Yup - me too when I first looked at.
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-30T14:42:11.620Z
Answers.LastActivityDate: 2024-10-30T14:42:11.620Z
Answers.UserDisplayName: Coleman
Body: <p>Search Kit is returning seemingly strange results. E.g. I am searching for Contacts who have a contribution. I expect Search Kit to return list of contacts, but it returns list of donations. That is, contacts are listed multiple times (one time for every donation).</p>
  <p>If I choose to Group by Age bracket (as recommended here: <a href="https://civicrm.stackexchange.com/questions/43194/how-to-count-individuals-by-age-bracket">How to count individuals by age bracket?</a>), then I get spectacularly wrong results. Probably, total amounts of donors/total sums are counted multiple times (for every donation a contact has made).</p>
  <p>In screenshot above I can Group contacts by Contact ID, then I get the correct number of results, but in that case I can't use grouping by Age bracket.</p>
  <p>How do I get a list of Contacts (every contact once) when looking for Contacts that have made a Contribution in Search Kit?</p>
  <p><a href="https://i.sstatic.net/vTGCWpPo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vTGCWpPo.png" alt="enter image description here" /></a></p>
  
Tags: <searchkit>
Title: Seemingly strange results in Search Kit? (Or, how do I...?)
ThreadText: # Seemingly strange results in Search Kit? (Or, how do I...?)
  
  (Asked by: username_0 on 2024-10-30)
  
  Search Kit is returning seemingly strange results. E.g. I am searching for Contacts who have a contribution. I expect Search Kit to return list of contacts, but it returns list of donations. That is, contacts are listed multiple times (one time for every donation).
  
  If I choose to Group by Age bracket (as recommended here: [How to count individuals by age bracket?](https://civicrm.stackexchange.com/questions/43194/how-to-count-individuals-by-age-bracket)), then I get spectacularly wrong results. Probably, total amounts of donors/total sums are counted multiple times (for every donation a contact has made).
  
  In screenshot above I can Group contacts by Contact ID, then I get the correct number of results, but in that case I can't use grouping by Age bracket.
  
  How do I get a list of Contacts (every contact once) when looking for Contacts that have made a Contribution in Search Kit?
  
  [![enter image description here](https://i.sstatic.net/vTGCWpPo.png)](https://i.sstatic.net/vTGCWpPo.png)
  
  **Tags:** searchkit
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2024-10-31. Score: 2
  
  You could do it in two steps:
  
  1. One SK to create a smart group of contacts who have made donations
     eg "Contributors"
  2. One SK to create a listing grouped by age bracket,
     with a filter condition of "In groups" "Contributors"
  
  > **Comments:**
  > **username_2**: Can searchkit use smart groups?  
  > **username_3**: @username_2 yes - there's a WHERE filter for Contacts (which is confusing because it seems like you should join Contacts to Groups, but that won't catch smart groups).  
  
  ---
  
  ### Answer by username_3 on 2024-11-01. Score: 1
  
  username_1's solution is workable here, because you aren't, e.g., asking for the totals of donations by age group. But if you did, there's a more advanced technique.
  
  You can use SearchKit results in a second SearchKit query. You can do that by creating a display of type "Entity". So if, e.g., you needed total amounts by age group:
  
  * You'd make one search of contacts joined to contributions, with total amounts, grouped by contact, then save it as an entity.
  * Then you could make a second query where you take contacts and join to the results of query 1. Then you group by age group.
  
  By pre-grouping in query 1, you take what would ordinarily be a "one-to-many" join (contacts to contributions) and turn it into a "one-to-one" join. That prevents any duplication of rows to throw off your numbers.
  
  This is actually the most common application of the Entity display - you need to group by two criteria without duplicate rows throwing off your results.
  
  
  ---
  
  ### Answer by username_4 on 2024-10-30. Score: 0
  
  SearchKit might seem strange at first if you are not familiar with the basics of SQL. You might be interested to read over an intro to SQL to understand how joins work. Basically, when you join one table to another, SQL will return a row for every matching join. You can find lots of illustrations out there to help you with the concept, like this one, which shows that a contact with multiple contributions will return multiple rows:
  
  [![SQL Join](https://i.sstatic.net/lQEh8A39.png)](https://i.sstatic.net/lQEh8A39.png)
  
  > **Comments:**
  > **username_0**: 1) Is there a way the Search search results return only unique contact ids (i.e. contacts rather than contributions) in such search? 2) This SQLish behavior also means wrong sums of Contact IDs (not sum of unique, but of every duplicate) and money when counting all together.  
  > **username_5**: that second blue line on the right is confusing me!  
  > **username_1**: @username_5 - note the top section is two separate tables.  
  > **username_5**: LOL. no i hadn't picked that up, just read left col and hten right col  
  > **username_1**: Yup - me too when I first looked at.  
  
  ---
  
  