0

How to get max value + another column?

I have column for my pet and another column for his weight

I'm trying to create a computed field that has both the "max" weight and the date that that weight occurred.

I've tried creating something like the below, but it does not work.

max((select Cats).cat + " " + text(WeighDate))

The first part does work, but I also want to see the date field where that max value was found.

Easy to do in standard SQL, but I don't see how Ninox expects me to do this...

How to do?

6 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 2 yrs ago
    • Reported - view

    If the first part is correct, you can assign a variable to this select function and get the two values of the record:

    let i := max(select Cats).cat
    i.cat + " " + text(i.WeightDate)
    
      • ninox.1
      • 2 yrs ago
      • Reported - view

      RoSoft_Steven Rooryck That's cool, but the second line says: Expression does not return a record. Is there a minor change I could try?

    • Fred
    • 2 yrs ago
    • Reported - view

    Just change the first line to:

    let i := last(select Cats order by weight)
    i.cat + " - " + i.WeightDate

    The change in line 1 adds the order by command so we select all records from Cats then order by weight then we pull the last one as that should be the heaviest. We have to make sure we don't put a field name after the select as that tells Ninox to only pull data from that one field and we need data from all fields.

    In line 2 we don't need the text command for date fields.

    I'm assuming that you will need to also filter the select so you can see weight by specific cat , so maybe something like:

    let t := this;
    let i := last(select Cats[name = t.name] order by weight)

    I don't know what table you are in so I'm not sure you can just use a this command, but you get the idea.

    If you already have a link to the Cats table from where ever you currently are then you don't need the select. If so then we can show you how to use the power of the relationship to get the data you need.

    I hope this helps.

      • ninox.1
      • 2 yrs ago
      • Reported - view

      @Fred

      It's just a single table. Very simple case.

      That's cool! It worked! I had to make a small change to order by the cat's name (which holds the weight).

      Say, is there anywhere where the Ninox SELECT statement is documented with all the clauses? It's so SQL like, but in practice error prone since it's not SQL.

      Thanks Fred. Awesome stuff!

      • Fred
      • 2 yrs ago
      • Reported - view
      Mike said:
      Say, is there anywhere where the Ninox SELECT statement is documented with all the clauses?

       Not really. Documentation is a particular weak point of Ninox.

      • ninox.1
      • 2 yrs ago
      • Reported - view

      Fred Thanks Fred.

      I hope somebody there is listening at Ninox central...as I hear that "poor-to-barely-existent-documentation" complaint over and over (and see it myself).