Jump to content
Server Maintenance This Week. ×

Counting Instances of a Recurrence in a Field


This topic is 4034 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have an input field, where the user can choose from a dropdown list between three non-numerica values (A,B,C), I'd like to create three fields which display the instances of the three values based on the data on the records, possibly sorted descending, so for example if the values in the field are: A,A,B,C,C,C the database should return:

 

C: 3

A: 2

B: 1

 

And if the user creates two new record with values A,A, it should become:

 

A: 4

C: 3

B: 1

 

How can I accomplish that?

Link to comment
Share on other sites

If I understand you correctly, I would use a calulcation field using patterncount to get the count of a's.b's, etc... Then create 3 summary fields to get the totals

Link to comment
Share on other sites

How do I use patterncount efficiently? I tried to look for examples but FMP gives a too short one to understand and on the net there are plenty of instances of it but all too complicated as opposed to what I want to achieve. Also, I need to evaluate the occurrences of A,B,C, in a number of records rather than in a single textbox, does it work anyways?

Link to comment
Share on other sites

Why not Attach a copy of your file. Remove any confidential information first. This will allow us to see your structure and either correct it or give you help so that you can do it yourself. It will allow us to describe things in your file naming of layouts, field names, scripts, etc.

 

Save a copy, zip it and follow these steps.

 

How to add an attachment to a reply.

Link to comment
Share on other sites

You are right.

I made a sample DB with a few records in it. There are 3 layouts, first one's the one where the user enters the data record by record (I did include a few sample records), second one's a sorted list and the third one's the one I can't achieve; I created a bunch of fields where I did manually input the data the way I would like them to appear with calculations, to visually give you an idea, more specifically:

- The first part should be a "top ten" where the DB checks the records and display the first 10 results ordered by descending High Score.

- The second part should display which are the most used cars, most used circuits and the most common weather (all text fields), along with the occurences.

- The third part should display a 'self updating' "top four" with the four available weathers sorted by occurences.

Test.zip

Link to comment
Share on other sites

Why not Attach a copy of your file. Remove any confidential information first. This will allow us to see your structure and either correct it or give you help so that you can do it yourself. It will allow us to describe things in your file naming of layouts, field names, scripts, etc.

 

Save a copy, zip it and follow these steps.

 

How to add an attachment to a reply.

 

Apparently making a sample DB to provide the "structure" of the database only had the effect to scare the heck out of everybody which priorly tried to help? :)

 

Does anyone, by any chance, know how I could tackle my problems?

Link to comment
Share on other sites

I still think you should do it the way I said above  please see attached file...

This solution helps me solving the "counting instances" problem on one hand, on the other hand it doesn't allow me to have them sorted like:

A: 5
C: 3
B: 1

but rather like

A: 5
B: 1
C: 3

Plus it doesn't let me determine which is the "most common occurrence". Any way these two things could be implemented?

Link to comment
Share on other sites

Add a calulation field  called most common  and use this script

this will give you the most common used.

Case(
suma >sumb and sumc;"A";
sumb > suma and sumc;"B";
sumc > sumb and suma;"C"
)

 

 

we can do the same thing to get the order is you need.

 

This way works well since you have only a few choices.. if their were more we might want a little bit more advanced approach.

 

case(

suma >sumb and suma>sumc and sumb > sumc;"A="&suma&¶&"B="&sumb&¶&"C="sumc;

etc...

etc...

etc...

)

 

 

if you need help with it I will be glad to code it for you if needed.

Link to comment
Share on other sites

Add a calulation field  called most common  and use this script

this will give you the most common used.

Case(

suma > sumb and sumc;"A";

sumb > suma and sumc;"B";

sumc > sumb and suma;"C"

)

This part seems pretty straight forward and I can easily replicate it, but as far as I understood, it would just return the most common value rather than an a "top five" ordered by occurrences (which is what I aim to)

 

 

we can do the same thing to get the order is you need.

 

This way works well since you have only a few choices.. if their were more we might want a little bit more advanced approach.

 

case(

suma >sumb and suma>sumc and sumb > sumc;"A="&suma&¶&"B="&sumb&¶&"C="sumc;

etc...

etc...

etc...

)

 

 

if you need help with it I will be glad to code it for you if needed.

This part is definitely beyond understanding to me, if you could code it for me I'd be grateful so I could try it out and 'add to my repertoire'.

As for the number of values, one "list" is made of just 4 values, another one has more than 10 entries, which is the more complicated approach you had in mind? Otherwise I could just replicate the system you mentioned and manually add lines as required.

Sorry if my post seems confused but apparently I have some problems translating what I want into words, thank you for your patience :)

Link to comment
Share on other sites

What I read above from you was

Plus it doesn't let me determine which is the "most common occurrence"

which is what that lets you do.

Please let me know exactly what you want and I will be glad to help.

thanks

Link to comment
Share on other sites

Let's say I got one field which may contain up to four values (A,B,C,D), say I have 10 records like this:

A: 5
B: 1
C: 3
D: 1
I would like to have a dinamycally changing "top four" which would return the following result:

A: 5
C: 3
B: 1
D: 1
I mentioned dinamycally changing since if I create ten more records where the data entered in the field is "B" I'd like to look like this:

B: 11
A: 5
C: 3
D: 1
Link to comment
Share on other sites

Did you try it?

LeftValues (

ExecuteSQL ( "
              SELECT
                  Circuit,
                  Count ( Circuit ) AS kount
              FROM Test
              GROUP BY Circuit
              ORDER BY kount DESC
             ";
                ""; ""; ""
           )

            ; 3
           )
Link to comment
Share on other sites

I'd love to but I am totally at a loss when it comes to SQL, I have no idea where should I write this function, if I should create a field, what kind of field should that be etc..

Link to comment
Share on other sites

If you are uncomfortable with it then you can use the fast summaries method.

 

If using SQL, in your case here you can either set a variable, use a calc field, set a field etc with it. What this SQL statement does is return the Circuit field and count of the Circuit field when grouping it by that field ( think subsummary report grouping or GetSummary ( ) function ). Then it is sorted in descending order based on that count result of that field ( I assigned an alias of 'kount' to it ).

Link to comment
Share on other sites

I have modified your file and attached it. I have left some notes for you in the field definition comment section as well as a screen shot of the inspector to show you where to modify the tab positions. You can change the column separator to be what you want. I gave an example of using the tab character as well as a space dash space " - ". The default is a comma.

 

 

top3_count.zip

Link to comment
Share on other sites

Okay, thanks to your help I managed to make it work, the reason why it wasn't working was because the FROM table was supposed to be one word only and in my case it was made of two words, but I changed it to one word and it now works.

Thanks a lot.

Edited by Mafia2020
Link to comment
Share on other sites

This topic is 4034 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

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