Forum Discussion

EmmaFinger1's avatar
EmmaFinger1
Qrew Trainee
2 years ago

Rank using a query

Hi everyone, 

I have a list of records that I need to rank, first by the expected start date, then by the final date required, then by the build priority, and last using the record ID.  One thing to note is that the expected start date field is usually blank.

This is the formula I am using currently, and it is working with the exception that if a record has the expected start date populated then it numbers those and then starts the numbering over again on the records that do not have a date entered in the expected start date.  For example if 2 of my records have an expected start date they would be ranked 1 & 2, then the next record (without an expected start date but with the earliest final date required) would again be ranked 1. 

I have referenced Quickbase Junkies videos which is how I got this far.  Any help/suggestions would be appreciated.

var text QZER = "{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{148.BF.'"&[Expected Start Date]&"'}";

var text QONE = "{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{148.EX.'"&[Expected Start Date]&"'}AND{129.BF.'"&[Final Date Required]&"'}";

var text QTWO = "{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{148.EX.'"&[Expected Start Date]&"'}AND{129.EX.'"&[Final Date Required]&"'}AND{47.LT.'"&[Build Priority]&"'}";

var text QTHR = "{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{148.EX.'"&[Expected Start Date]&"'}AND{129.EX.'"&[Final Date Required]&"'}AND{47.EX.'"&[Build Priority]&"'}AND{10.LTE.'"&[Record ID]&"'}";

 

 

Size(GetRecords($QZER))+Size(GetRecords($QONE))+Size(GetRecords($QTWO))+Size(GetRecords($QTHR))



------------------------------
Emma Finger
------------------------------

6 Replies

  • MarkShnier__You's avatar
    MarkShnier__You
    Qrew #1 Challenger
    An alternative would be to create a concatenated field which would combine all 4 fields  and will sort correctly and then just run the Formula Query against  that single field.  You would need to convert the dates to strings like

    20220719 (ie July 19, 2022)

    You will need to control where fields with missing dates sort, at the top or the bottom.  You can do that with the formula which makes the YYYYMMDD portion of the concatenated field.


    ------------------------------
    Mark Shnier (Your Quickbase Coach)
    mark.shnier@gmail.com
    ------------------------------
    • EmmaFinger1's avatar
      EmmaFinger1
      Qrew Trainee
      Thank you for the suggestion Mark, I should have specified that only 3 of the 4 fields are date fields.  The Build priority is a numerical ranking 1, 2, 3.  I believe what you are suggesting would only work if all 4 of the fields are date fields, but perhaps I can append the build priority to the end of the date fields to still make this work.  I will give that a try.

      ------------------------------
      Emma Finger
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Qrew #1 Challenger
        For my suggestion the components of your concatenated field do not have to be date fields. I was just pointing out that a date field needs to be in the format YYYYMMDD in order to sort correctly.

        ------------------------------
        Mark Shnier (Your Quickbase Coach)
        mark.shnier@gmail.com
        ------------------------------
  • Hi @Emma Finger

    I like the suggestion from @Mark Shnier (Your Quickbase Coach). It may be cleaner than my solution below if you can get it to work.

    Looking at the way you have it set up now....

    Because the blank start dates won't be ranked in your first queries, I'd suggest setting up something like this where you first handle the scenarios where they are not blank, then create rankings for when they are blank (only start the ranking after the total that have start dates).

    If(not isnull([Expected Start Date]),
    Size(GetRecords($QZER))+Size(GetRecords($QONE))+Size(GetRecords($QTWO))+Size(GetRecords($QTHR)),
    Size(GetRecords("{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{148.XEX.''}")) + Size(GetRecords($QONE))+Size(GetRecords($QTWO))+Size(GetRecords($QTHR)) )
    ​​
    Let me know if that does the trick.

    -Sharon



    ------------------------------
    Quick Base Junkie
    Quick Base Junkie
    https://quickbasejunkie.com
    ------------------------------
    • EmmaFinger1's avatar
      EmmaFinger1
      Qrew Trainee
      Thank you @Quick Base Junkie I did test the option you posted and it also works, but as you said, the solution from @Mark Shnier (Your Quickbase Coach) is cleaner and will probably be easier to maintain when I undoubtedly get asked to add more fields to the calculation.
      ​​​

      ------------------------------
      Emma Finger
      ------------------------------