Result Value Different in Expression Testing Then on View or Db

Hi All,

I have an expression setting the value of a percent column. When I test the expression it work perfectly. Currently it should be 100% done with a value of 1.00 and that is what the test result shows. Now when I view this data either in the form or in the database after it is saved for some reason it is 20%. It seems that my expression where I am using SELECT() functions work correctly during testing but are not working as expected outside of testing. Any idea why this would be? This is the first time I have had a test value that is different than the actual so I am not sure how to trouble shoot this one.

Database
3X_e_c_ec808cb4a80b60ae2399459b59b2460bcfd5b438.png
Testing
3X_8_4_84faa4c1bdcce626d50487dd1534833dccb08706.png
Form View

0 9 258
9 REPLIES 9

Did you ever get a solution to this?

+1 expression testing showing the correct result but the app or data is wrong

AppScript must be buggy!?

I have an amount calculated based on a time duration (the Hourly Rate used here is $60, I'm also rounding to the nearest 15 minutes)...

 

 

 

IF( Round(Totalhours([Duration])*60+14)/15*15/60.0 > 0, 
   (Round(Totalhours([Duration])*60+14)/15*15/60.0)*DECIMAL([Client].[Hourly Rate]),
   0

 

 

 

It works perfectly when testing:

  • AppSheet1.png

However, rendered in the app it looks like this!?  Huh?!

  • AppSheet2.png 
    This first Due of $399 should be $390 - $60 X 6.5 hours. I get the whole precision problem, but this is wild!

OK, so I thought maybe it had to do with using a spreadsheet as a source.  I built the same with AppSheet DB and here's a side-by-side comparison after updating the record with the formula shown in my previous post.
I made this a TEXT field so I could see various values - factor and due - but results were the same if it was a PRICE field...

Screenshot 2024-02-02 3.52.10 PM.png

The above is the Test run on the expression/formula running from the AS DB version and what is showing in the preview pain (to the right). This result (same expressions used) had different values then what I am getting in the gsheet source app (see my 6.5 hours example above)!! 

See below - as compared to my previous post...
Screenshot 2024-02-02 3.59.00 PM.png
What am I missing?! ๐Ÿค”

This is not a precision problem.  I suspect values are not converting/calculating like you expect.

Please show all the bits and pieces. 

  • What does the raw data look like, for both Rate and Hours, in the datasource?  (maybe AppSheet values are being rounded for display?)
  • How is your Duration of "6:30" being derived?
  • How are you converting the Duration of "6:30" to the decimal of "6.5"?
  • How are you building your test strings?

Hi @WillowMobileSys thanks for the questions! See my post below, I'll consider this the solution for now. 
I think I was over complicating matters, but yes, there certainly does seem like rounding gets funny when it comes to Time values and converting them!!  

UPDATE:
 In case you are interested, I've had a bit more time to respond.  Your questions are in Blue \ @WillowMobileSys :    

I have a Client and Tasks table used for my app.
(is there an easy way to capture table definitions for posting?)  
Tasks is now changed to what I posted below. So likely not that helpful. 

  • What does the raw data look like, for both Rate and Hours, in the datasource?  (maybe AppSheet values are being rounded for display?)

    Rate is defined in a Client table as:
    KGingeri_0-1706924510620.png

    Hours was a TEXT field (changed now) where I tried to assemble (via an expression) the "HH:MM" text Using another DURATION field in my Tasks Table and from [Stop] - [Start] TIME values entered by the user. These are also rounded to the nearest higher 15 minute mark. 

  • How is your Duration of "6:30" being derived?

    Simply in a DURATION field from "[Stop] - [Start]" times entered - a "Formula" in the Tasks table.

  • How are you converting the Duration of "6:30" to the decimal of "6.5"?

    An expression (or Formula - are they synonymous?) as this:
    Round(Totalhours([Duration])*60+14) / 15 * 15 / 60.0

  • How are you building your test strings?

    A expression/formula as follows (this is now changed though, to an expression using MOD() function):
    IF(Number(Index(Split([Duration],":"),2))+14.0 > 59,
      Text(Number(Index(Split([Duration],":"),1))+1),
      Text(Number(Index(Split([Duration],":"),1)))
    )
    &IFS(
      Number(Index(Split([Duration],":"),2))+14.0 > 59, ":00",
      Number(Index(Split([Duration],":"),2))+14.0 > 44, ":45",
      Number(Index(Split([Duration],":"),2))+14.0 > 29, ":30",
      Number(Index(Split([Duration],":"),2))+14.0 > 14, ":15",
      Number(Index(Split([Duration],":"),2))+14.0 < 15, ":00"
    )

I am pretty sure that AppSheet has issues with TIME value conversions in general.  This was another one I posted and must of the info of what I was doing can be gleamed from the test result capture - formula, headings show data types, etc.  The test result is good - rendering bad.

KGingeri_2-1706928171160.png

I've since fixed this as well - see this post . None the less, I don't know why this didn't work - even if it was overkill. ๐Ÿ˜„

 

Oh my, I think too much like a programmer maybe, but if I simplify this formula to just this:

 

TOTALHOURS([Duration]) * [Client].[Hourly Rate]

 

..it works just fine! ๐Ÿ˜„
I didn't realise that TOTALHOURS() gives a decimal value - hence the factor I needed to calculate the amount.

I still don't understand why it doesn't render correctly in the above examples though.


@KGingeri wrote:

I still don't understand why it doesn't render correctly in the above examples though.


Where are you seeing the differences and how are they being built/derived/calculated?


 

@WillowMobileSys I don't have much more to share than what's in this thread.  A basic summary is:

  • I assembled a duration in text form, as AppSheet didn't allow me to populate that field type. This was for sake of displaying in a HH:MM format in the app.
  • I than used string functions to pull apart those text hours and minutes to create a "factor" I could multiply by 60 (minutes in an hour), to then multiply by the client rate (a Price field) to get the actual amount owing.
  • Testing all of this worked fine and gave expected results
  • When rendered in the app the values were incorrect, and not just as a result of precision. I had a value of $399 (app display) instead of $390 for 6.5 hours, charged at $60 per hour.

That's really all I have to share. I've abandon plans to display the duration in that form and just store and display it in decimal. Rendered in the app all works this way.

So my problem is solved.

Top Labels in this Space