Math in multiple fields on the same record

Options

Hi guys,

I have a data base structure where there is 8 fields as doubles and one text field.

When I query the records, I would like to calculate an average of the 8 fields.

I tried to create a new variable starting with 0 and set up a function stack to add numbers. When I put the value to be added like db.field I got an error message telling that the field should be a number.

I'm not sure if I'm the right field notation. What I need to add the information store in the field.

Any clue on what I'm doing wrong?

Thanks

Gustavo

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    If you share a screenshot, I think we could be more helpful!

  • Gustavo Santos
    Options

    Sure.

    I query all results from the record wheel. Than create a variable AVG that should add the value of the fields.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    edited June 2023
    Options

    Most likely you are returning a list in query all records, and so references to that list get you arrays of numbers rather than thenumbers themselves. Is the query supposed to return multiple records? If so, you might try setting up a for-each loop to generate the averages for each record inside that.

    This multidimensional data manipulation is a frequent topic on Statechange daily office hours and loom-enabled forums where we teach you to crack the hardest 5% of projects.

  • Gustavo Santos
    Options

    So far, I have only 1 record. The addition I’m doing is to pick fields from this record.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Yes, but is the output type "list" or is it "single"?


    You can have a list that contains one record - it's like the holding an apple, vs holding a plastic bag that has one apple. You'll notice the difference when you try to take a bite.

    Check the output tab of your "query all records" - you can change it there.