![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, I'm using FMP6. I've got two databases. One ("A") consists of three fields, one of which ("Foo") serves as a value list for a field ("Bar") in the other ("B") database. Now, I want to add a field to database A that serves as a reporting function. What this field would do is reflect how many records in B have the field Bar containing the contents of this record's Foo. Or to explain it another way, I just want a field in B that shows how many records in A use the value that's in B's Foo field. An example of how it would look without the report fields: Database A Record 1, field Foo: "Blah" Record 2, field Foo: "Crap" Database B Record 1, field Bar: "Blah" (<- via a Value List pointing at A::Foo) Record 2, field Bar: "Blah" (<- via a Value List pointing at A::Foo) Now, I want my report fields to make database A look like this: Record 1, field Foo: "Blah", field CountInB: 2 Record 1, field Foo: "Crap", field CountInB: 0 But I don't know how to create that relationship. I don't mind if it's not an auto-updating number; I could just create a script to loop through the records when the report is needed. I've tried looking at self-joining and other things, but I haven't yet figured out how to make it work. I hope I've explained myself clearly enough... If I haven't please let me know and I'll try again. I hope somebody here can help me. Thanks! Steve Freitas Costa Mesa, California Hey there, |
#3
| |||
| |||
|
|
I think I would do this : in second database, auto-enter number field called 'Constant1'. Define as auto-enter data = 1, disallow changing. In first database, set up relationship to second database, foo to bar. In first database, create calculation number field = sum(foo\bar::Constant1) |
|
When a record matches in second database Foo to first database Bar, its Constant1 value will be added to the sum of all other matching records and displayed on the appropriate record in the first database. |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Hi Kurt, Thanks so much for your reply! I'm working on implementing it now. A few questions, though. You mention to do this: I think I would do this : in second database, auto-enter number field called 'Constant1'. Define as auto-enter data = 1, disallow changing. In first database, set up relationship to second database, foo to bar. In first database, create calculation number field = sum(foo\bar::Constant1) Hmm, from A my relation right now doesn't involve B::Constant1, it's from A::Foo to B::Bar (or, as read from the define relationships window, "Foo = ::Bar, Related File is B.fp5"). And I'm confused by the use of the backslash. |
|
I tried doing field = Sum(B::Constant1), but that obviously doesn't give me what I want. Hrm. I'll keep poking at it. When a record matches in second database Foo to first database Bar, its Constant1 value will be added to the sum of all other matching records and displayed on the appropriate record in the first database. I don't quite get it, as foo is a text field, not a number, yet I'm trying to divide it by 1? No, that's a backslash... So I guess I'm missing what that bit's referring to. Just as a reminder, my terms are defined as such: Database "A" Field "Foo" Database "B" Field "Bar" Thanks again! Steve |
#8
| |||
| |||
|
|
Ah, okay, I think I got it figured out. I replaced B::Constant1 with a field which calculates whether that record is in the desired date range, then coughs up a 1 or a 0 as a result. Then when A calls Sum(), it doesn't have to worry about any date issues; it just adds up all those calculated 1s or 0s and arrives at the desired result. Thanks again for all your help! Steve Wow, you covered a lot of territory in the last couple of posts. I |
#9
| |||
| |||
|
|
Wow, you covered a lot of territory in the last couple of posts. I should have checked them before making my own reply. Say, do you sleep? I thought you were in Pacific time zone, but you seem to be posting round the clock. |
|
Anyway, congrats on your advancements thus far. You're definitely on to a sticky bit when you try to set up relationships that use dates. Matching an exact date is easy enough, doing an inequality is not too bad, but matching a start and end date range is nice and chewy. I have to do it in a couple of relationships at my work, where we allow a user to set a beginning and ending date and match transaction that lie between. |
|
If you can get away with selecting your dates in the 'source' file and just summing from the 'report' file, good. Do it. |
![]() |
| Thread Tools | |
| Display Modes | |
| |