6 Replies Latest reply on May 23, 2017 6:57 AM by J_File

    Counting entries in filtered portal

    J_File

      Hi all,

       

      I want to be able to display the total number of rows in a portal in the portal header like this (click on the image to see the count of rows on the far right hand side):

      Snap 1.png

      I am doing this by creating a new field like this:

       

      Snap 2.png

       

      I plonk that field on my layout and all works as expected.

       

      Thing is, I have the odd set of data where I am using filtering on the portal to display different bits of the same data. The counting method I am currently using only returns the total number of results as if the filtering was not being applied. Any ideas on how to count the number or rows in a filtered portal? Or in this case, should i just be creating a new relationship to display the rows I want to see as opposed to using the easier (and lazier) method of using the inbuilt portal filtering?

       

      Thanks in anticipation of a helpful response!

       

      James

        • 1. Re: Counting entries in filtered portal
          erolst

          Try this:

           

          • create a summary field type Count of: primary key in the table that your portal points at.

          • add a one-row portal with the same filter calculation to your layout

          • place the related summary field into the portal

          • give the field an object name

          • use GetLayoutObjectAttribute ( "objectName" ; "content" ) to get the filtered count (you don't need a field, but can use e.g. a one-segment button bar and its label calculation feature to calculate and display the value)

           

          Note that the one-row portal can be hidden or placed outside the layout proper.

          • 2. Re: Counting entries in filtered portal
            TomHays

            I would do something very similar to erolst except I would define the new field in the portal target table as a Calculation with the definition Get(FoundCount) with the Storage Options... as "Do not store calculation results".

             

            This does not require that the table have a primary key, and it may offer a performance advantage.

             

            -Tom

            • 3. Re: Counting entries in filtered portal
              erolst

              I'm with you on that one ...

               

              TomHays wrote:

              I would define the new field in the portal target table as a Calculation with the definition Get(FoundCount) with the Storage Options... as "Do not store calculation results".

               

              ... it may offer a performance advantage.

              ... but ...

              TomHays wrote:

              This does not require that the table have a primary key

              ... a table that has something worth counting (i.e., all tables with the exception of utility, 'Global' etc. tables) should have a primary key.

              • 4. Re: Counting entries in filtered portal
                beverly

                The

                Get ( FoundCount )

                in the chlld table can be used not only for the portal (filtered or not) in the parent, but also for the report-from-child.

                 

                The summary field (in Child) may also be used for the parent-context portal and child-context report.

                 

                TRUE: every table should have a primary key

                 

                But the calcution field (in parent) to count the child records may not be as useful (should you need the field in the child). One field, many uses.

                OR

                BTW, the Merge Symbol

                {{FoundCount}}

                may also be used in a portal (filtered or not), if the aim is display. (NOTE: no field created in either case.)

                The use of

                GetLayoutObjectAttribute ( "objectName" ; "content" )

                can still be helpful should the value be needed other than for display (in parent).

                Beverly

                • 5. Re: Counting entries in filtered portal
                  J_File

                  Thanks for the advice - I got a bit confused and did it the way that makes sense to me. I just created a couple of extra relationships (Anchor Buoy Method), assigned a couple of text constants and hooked the keys up as with the original portal but linked the text constants in as well. Job done.

                   

                  I am still very much a novice at FileMaker, but this works well.

                   

                  Not a clue if it is not as speedy, but the most rows I can envisage seeing in these portals are around 20 to 25 so don't think there will be issues in usability.

                   

                  Thanks once again for taking the time to try and help.

                   

                  James

                  • 6. Re: Counting entries in filtered portal
                    J_File

                    Hmm, that has messed something further down the line now. Need to retrace my footsteps and will try to do what you originally recommended.

                     

                    J