Updated: Jul 30
As for equations in your Knack database app, the order in which they appear (top to bottom in your table) is quite important for the calculations to be correct. Equations use other fields to derive their values, and those other fields can change based on all sorts of things. If Knack runs the equation BEFORE the equation's values are updated ... well, you have a problem. Here I do a simple demonstration showing what I'm talking about and what to look out for.
Interested in my Knack database app services? ... Book a call with me here: https://calendly.com/daveparrish/callwithdave
Full Transcript of this Knack Database App Post
0:00 Hey folks, Dave Parrish here to share from Knack Builders. I got another video that should be pretty quick. Today's topic is equations and what's called order of operations. 0:11 Knack has a brief article on this. But what it is, is both equations and text form is actually, You have to be in a certain order. 0:23 If they're using other values, and when I say order, I mean above or below of your list of fields. Equations use other fields to result in what they're going to result in. 0:37 And it only makes sense that if they're grabbing a value, ,in the equation, and that value is updated for whatever thing you're doing. 0:46 It could be a number of stuff. Conditional rules, drawn-in accounts, sum functions, whatever. If that value isn't updated if that value actually is updated after the equation runs, you're going to have an issue. 1:00 And I run into this on a regular basis. I'm just going to take you through what the deal is. I'll be right back. 0:00 Okay, let's go for it. To demonstrate what's going on here I just made up some fake app here sort of like an inventory thing and I just have a few fields. 0:12 Part name we're gonna since inventory we're gonna enter a starting inventory that's number the price of this I The number that it's been ordered now this was a more complex app this number would be generated by looking at line items on invoices but that's another deal. 0:30 Then two equation fields the current balance which is going to subtract the starting inventory minus the number that has been ordered. 0:40 And the current value which will take the current balance times the item price. Now these are in the correct order and let's go to a little demonstration thing here let's just pick some numbers. 0:53 50 let's say we get 50 starting balance let's say they cost 10 bucks a piece. And let's say that 10 have been ordered. 1:06 So all this math is right number ordered current balance value of 400. Now let's go screw up the works. Now this if you were building this you most likely would do this in the logical order but apps can really complex with all sorts of calculations. 1:25 And you can be adding and adding things. Things you didn't think of the first place and you're adding them to a table here that's got all kinds of values. 1:35 And you can lose track of where you were with that stuff. So if you ever see the formula that just went wrong, you're saying what's wrong, Mac? 1:43 Why isn't this working? Go check the order of operations first and make sure that they're in the right place. I'm just going to move these. 1:50 Okay, current balance. I'm going to take something and move it. So now they're above some other values. So what happens is NAC that runs this equation and it's going to go look at what this is, this is, and this is. 2:04 But these are being updated after the equation runs. So let's take a look here. Let's refresh the screen. Over here, notice 400. 2:17 Let's just change this to something. Let's change this to 100. Still 400, so that's wrong. And if you see that thing, first thing you want to do is check your order of operations. 2:34 Now if you run it again, let's turn this to 100, submit it, watch it, it's going to make itself right. 2:40 That's because it's. It's already updated the value, but that's all I got for this. It's important. And again, it applies. 2:48 I have a one right now with a lot of drawn in text formulas that create special names and they're all over the place. 2:57 And I ran up some issues there, even though I'm pretty experienced with it. It was an update. And these, how I thought, and then I went and checked that word of operation. 3:05 I'm like, ah, man, this should be after that. And there was lots of them. So it can get, it could be a mix of them and you can lose track. 3:11 So good luck with that. Thanks.