Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms 5 › Getting a NULL result on a calculation
- This topic has 6 replies, 3 voices, and was last updated 8 years, 4 months ago by
Oakwine.
-
AuthorPosts
-
June 14, 2017 at 11:37 AM #23516
OakwineParticipantI am attempting to perform a calculation on a numeric field that sometimes contains NULL values. I would like the calculation (60*field1/field2) to give the result NULL for a record where that field1 is NULL, but instead I’m getting a 0. I tried if(field1 is NULL, NULL, 60*field1/field2), but that didn’t work either.
June 14, 2017 at 2:24 PM #23517
BrendanKeymasterIf you don’t need to use the Calculation field in anything else, you could have it return Text instead and use
IFEMPTY(Field 1, "", 60*Field 1/Field 2)Then you’ll get an empty string as the result or the value otherwise.
June 14, 2017 at 3:25 PM #23520
OakwineParticipantI was planning to run an average of the calculated value (one-to-many relationship). Since there are old records for which I won’t have an entry for field1, I want to exclude those records from the results, otherwise the average will be incorrectly low.
June 14, 2017 at 9:33 PM #23524
BrendanKeymasterI’ll have to make some changes to the Math parser then because right now it returns either a String or a double. And a double can’t be nil.
June 15, 2017 at 7:18 AM #23527
OakwineParticipantThis isn’t critical, so I can wait. Thanks for figuring this out for me!
June 22, 2017 at 8:13 PM #23572
Mike SchwartzParticipantOakwine,
Maybe you can create another calculation field called “field1NOTempty” on your child form that returns a value of 0 if your 60*field1/field2 calculation field has the value of zero, and a value of 1 if the calculation field is not zero. Then on the parent form, instead of using an AVERAGE function on the calculation field, compute TOTAL(calculation field) divided by TOTAL(field1NOTempty).
— Mike
June 27, 2017 at 8:16 AM #23612
OakwineParticipant(I was away for a bit)
Mike, thanks, that was so close to what I needed. My ‘field1NOTempty’ needed to be calculated using Brendan’s IFEMPTY(field1,0,1) instead (because 0 and NULL are separate possible values for field1), then I could use your second formula correctly.
So now it works! Thanks everyone!
-
AuthorPosts
You must be logged in to reply to this topic.