Jump to content

Get count of related records with specific field value


Recommended Posts

  • Newbies

Hello,

Here is my scenario. I have two tables. One with dog houses, each record has information about the doghouse, etc. Second I have a table with each individual dog, each dog is linked to a doghouse by a housing ID. Each dog also has a status of "Active" or "Otherwise." What I want is each doghouse to have a count of how many "Active" dogs are linked to it. I can then do searches and calculations based on that.

Is there a way to have a doghouse record value that is a calculation, or will I need to write up a script that is run every time I want a report. 

As a side note I have some 6,000 doghouses and close to 60,000 dogs registered. The faster it works the better.

 

Thanks in advance!

Link to post
Share on other sites

You can have a calculation field in the DogHouses table =

ValueCount ( FilterValues ( List ( Dogs::Status ) ; "Active" ) )

However, such calculation will be unstored, so if you plan to "do searches and calculations based on that", you might be unhappy with the speed. If this is for a report, it might be preferable to turn this task over to the script that produces the report.

 

  • Thanks 1
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Similar Content

    • By Tony Diaz
      The tables.
      Items::ID
      Items::Item
      Items::Publisher
      Items::Date
       
      The Genre data is already arranged like this:
      Genre::ID (Unique Key)
      Genre::Name
      Genre::Category_ID
      Genre::Category

      The Platform data is 'simple'. ID and Name. But each item could be multiple platforms.  (Example #1 vs. Example #2)
      Platforms::ID
      Platforms::Name
      An item can have multiple Genre Categories related to it, and those usually have a single choice from within their Category, but might have multiples.

      It's supporting the possible multiples that I'm trying to work out. At this point there's 15 possible Genre Categories that each Item could have a selection from. Most have 4-6 of them.

      Example 1: Items::Table on the left, Genre::Table on the right, with some Genre Categories (Genre, Perspective, Pacing, Gameplay, Interface, Setting) and their sub-options.
      This one has just one sub-option per category.

      Example 2:  The Gameplay Genre Category has two sub-options related to it.



      Example Genre Table content:

       
      Just cracking the surface on One to One and One to Many relationships, I don't think this scenario is quite covered this way.

      Would each of those Genre Categories be portals showing only their related category ID?

      I presume that I would add fields to the Items::Table so I can pull related records:
      Items::Platform_IDfk
      Items::Genre_IDfk
      Items::Category_IDfk
      But those only support one relationship.
      Would I make value lists from those Genre Categories and Platforms and set them as tick box fields?
       
    • By St3v1e
      I’m new to FMPA 18, and have been “playing” with it over the past few months after being asked by my supervisor to create a small database to keep track of our customers. Nothing too fancy, but just enough that we can search for a name/company, create a few notes and print a pdf/invoice when required etc.
      I’ve been creating a few test databases and have checked out hours and hours of online tutorials, but this particular issue has me confused & frustrated.
       

      I’m trying to figure out how to have many contacts (employees) associated with one company (many to one?). I created a portal in the “Contacts” layout which references only the “CompanyName” field in the “Companies” table, and then created another portal in the “Companies” layout to show all employee’s in that company.
      My setup:-
      Tables:
      I currently have a “Contacts” table, and a “Companies” table, and will eventually add the “Notes” table before looking into more complex items (pdf’s etc).
      Fields:
      Both tables have Primary Keys (formatted as Text) setup to use the “Get( UUID)” reference (“Calculated Value” box in the Options/Auto-Enter window with also the “Do not replace existing value of field (if any)” box). Also in the same Options/Validation window, I’ve checked “only during data entry”, “Not empty” & “Unique Value” to complete the Primary key setup.
      I’ve followed this same process for the “Companies” table PK field.
      Next I created a foreign key (“company_id” - my PK’s are upper case, and FK’s lower case), which is formatted as “Text” in both tables and has no other formatting or field “Options” applied.
      Finally, in the “Relationships” tab, I initially connected the PK (Contacts) & FK(Companies) together and checked “Allow Creation of records in this table via this relationship” in the “Company” table. (See attached screenshot)




      The problem:
      When I create a new record in the contacts layout, and then add the company name, a new company is added in the companies records. But when I create subsequent contacts and add the same company, a new RECORD in the companies Records is created. Only one employee shows up in each “Companies” (portal) record.
      I also tried removing the relationship between the PK and FK, and using a text field in each named “Company” - this produces a list of employees in the “Contacts” portal window (Companies Layout), but again adds a new record which duplicates the first record. If I then add a third record I have 3 employees and 3 records in the Companies Table.
      Obviously I don’t require a new record every time I enter the same company name but want to reference each employee to a single company record, so I’m missing something and have not yet been able to find a tutorial which helps.
      Hope the above is not overly confusing.
      Any feedback or help very much appreciated.
      Insert existing attachment  
    • By owangolama
      Here is my situation.
      I have a 25x25 grid - let's call it a map. Think of it like a game board, like Battleship or perhaps an Excel spreadsheet.
      I have a 9x9 view of this grid since it is not possible for a phone user to practically view 25x25, but 9x9 seems to work fine.
      And I have the concept of Current_Location on the map, which is dynamic and changes based on other factors.
      In TABLE1 I have records of all the "cells"  in the 25x25 map that hold information about the cell (for example, the color of the cell). There is other information stored here that includes, for example, whether you can "see" other cells from this particular location in the grid. So in the record for, say, cell B5, I have a field that houses a return-delimited list of the other cells that can be "seen" from this cell (B5 in this instance).
      Another table, TABLE2 has records that are also have a field for Current_Location, and it tells me which cells (of the 25x25 grid) should be displayed in the 9x9 grid. Usually, the Current_Location is the middle cell in the 9x9 grid, but if the Current_Location is on the edge of the 25x25 grid, then the 9x9 view is adjusted accordingly and the Current_Location is shown on the edge of the 9x9 grid. The user can also change their orientation so they can view the map from a different direction. The way I store this information is in a field that simply lists (return-delimited) all the cell that should be shown in the 9x9 grid. So in our previous example of B5, the record for B5 has a field called Grid that is a list of the 81 cells that should be shown in the 9x9 grid.
      For other reasons, I cannot combine these two tables even though they both are based on the concept of relating information to Current_Location. TABLE1 is actually not as simple as described, but I'm trying to limit the scope of my question.
      So here is my question: I have 81 (sigh) objects on my layout for this 9x9 grid. I need to access information in TABLE1 for each of the cells that are represented in the 9x9 grid.
      For example, let's again assume that my Current_Location is B5 and by using TABLE2 I know the names of all the cells shown in the 9x9 grid (they are stored in a list in a field in TABLE2). How do I then get information about each of those 81 cells out of TABLE1. I.e., each of the 81 cells should be colored according to information in TABLE1.
      So, for the top-left cell in the 9x9 grid (which appears as the FIRST item in the list field in TABLE2), I need to be able to look up the color in TABLE1, and use it to drive Conditional Formatting of the cell. So if Color(B5)=3, then make the background color of the cell green. I can grab the cell name, and could easily write a script to figure out the color, but I need to *look up* the color to use it in Conditional Formatting.
      I was trying to generate another field somehow that was an analogous list of 81 items that showed the color of each of the 81 cells (in the correct order), but 1) I couldn't figure out how to do that without running a script (which would take too long since these things are changing frequently and I really just need a data lookup); and 2) I think there must be a much cleverer way. I am still very new to join tables, but I think the answer is in that arena somewhere. The other idea I had was trying to write a Custom Function since I can easily grab the name of the cell, B5. But I don't know how to create such a function since it needs to access a particular table and it seems like functions don't really work that way.
      Thanks in advance for any help!!
    • By alanf
      I have a table named Sales with the following data:
      ----------
      ID
      DATE
      UNITS
      -----------
      Based on Sample data below, i am trying to query the table by creating a relationship to find the ID that achieved a specified Unit amount on the earliest date.
      In other words, and for example, which ID achieved a specified Unit amount first (earliest date)
      Specified Unit Amt of 5 = 1 Expected records returned result
      301 10/13/2018 6.5 Specified Unit Amt of 2 = 2 Expected records returned result
      766 10/03/2018 2 360 10/03/2018 2  
      I think a selfjoin may be required.  Any thoughts appreciated!
       
      Thanks
      Alan
       
      SAMPLE DATA
                                         ID                          DATE                                     UNITS
      301 10/15/2018 9 301 10/14/2018 8.5 301 10/13/2018 6.5 360 10/14/2018 5.5 305 10/15/2018 5.5 301 10/12/2018 4.5 656 10/13/2018 4.5 360 10/13/2018 4.5 305 10/14/2018 4.5 611 10/14/2018 4.5 305 10/13/2018 4 15 10/13/2018 4 301 10/11/2018 3.5 360 10/12/2018 3.5 611 10/13/2018 3.5 301 10/09/2018 3 15 10/11/2018 3 656 10/12/2018 3 611 10/12/2018 3 200 10/14/2018 3 301 10/06/2018 2.5 611 10/09/2018 2.5 200 10/13/2018 2.5 766 10/03/2018 2 360 10/03/2018 2 785 10/05/2018 2 301 10/05/2018 2 611 10/05/2018 2 439 10/10/2018 2 656 10/11/2018 2 510 10/15/2018 2 360 10/01/2018 1.5 510 10/04/2018 1.5 611 10/04/2018 1.5 305 10/05/2018 1.5 200 10/08/2018 1.5 656 10/09/2018 1.5 785 10/02/2018 1 766 10/02/2018 1 305 10/03/2018 1 439 10/03/2018 1 15 10/04/2018 1 301 10/04/2018 1 200 10/07/2018 1 656 10/08/2018 1 766 10/01/2018 0.5 510 10/01/2018 0.5 611 10/01/2018 0.5 200 10/06/2018 0.5
    • By Richard Carlton
      Summer is over and our weekly FileMaker webinars are back! 

      Our first one is this Thursday at 11am PDT, on “Relationships for Beginners”. 

      Register Here: 
      https://attendee.gotowebinar.com/register/6892433068111504642 

      We will spend 30 minutes covering a specific topic. Then the last 30 minutes will be an open Q&A on any topic.

      Topic List:
      Sept 13th: Relationships for Beginners
      Sept 20th: Find Records, Date Ranges, and Special Operators
      Sept 27th: Conditional Formatting (Can I making something Red?)
      Oct 4th: Automation (Repetitive Tasks can become Scripts)
      Oct 11th: Reporting & SubSummaries
      Oct 18th: Merge Fields and Hiding Objects (Harry Potter Invisibility Cloak)
      Oct 25th: Sharing your FileMaker App with Co-Workers
      Nov 1st: Basic Concepts for Building Mobile Apps


      All the best, 
      Richard Carlton 
      CEO & Video Trainer

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.