Discussions

 View Only
  • 1.  Rank using a query

    Posted 07-18-2022 23:10
    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
    ------------------------------


  • 2.  RE: Rank using a query

    Posted 07-19-2022 08:37
    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
    ------------------------------



  • 3.  RE: Rank using a query

    Posted 07-19-2022 14:49
    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
    ------------------------------



  • 4.  RE: Rank using a query

    Posted 07-19-2022 14:55
    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
    ------------------------------



  • 5.  RE: Rank using a query

    Posted 07-19-2022 19:34
    Thank you @Mark Shnier (Your Quickbase Coach) I did end up using your solution and added a field that changed the format of the date field and appended the build priority to the end of it with a dash. 
    If(IsNull([Expected Start Date])=false,(ToFormattedText([Expected Start Date],"YYYYMMDD")& "-" & [Build Priority]),
    IsNull([Expected Start Date])=true,(ToFormattedText([Final Date Required],"YYYYMMDD")& "-" & [Build Priority]))

    I then used the new field in a formula to "rank" the records using the ranking option shared by @Quick Base Junkie in her blog post, which allows me to use the record ID as the differentiator when 2 records are otherwise the same (a tie), in the ranking.

    var text QZER = "{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{291.LT.'"&[For Build Order Combined]&"'}";
    var text QONE = "{289.EX.'true'}AND{58.EX.'"&[Region]&"'}AND{45.EX.'"&[Data Center Name]&"'}AND{291.EX.'"&[For Build Order Combined]&"'}AND{10.LTE.'"&[Record ID]&"'}";

    Size(GetRecords($QZER))+Size(GetRecords($QONE))
    ​​

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



  • 6.  RE: Rank using a query

    Posted 07-19-2022 18:37
    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
    ------------------------------



  • 7.  RE: Rank using a query

    Posted 07-19-2022 19:37
    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
    ------------------------------