0

Limit the number of rows visible in a table view

Hello !

I have a table view on my dashboard that sorts customers by amount spent. I would like it to display only the 5 customers who made the biggest expenses.

Is it possible ? And if so, how can I do it ?

5 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    You can take your select and then use the count() and slice() functions.

    let yourSelect := select.... order by expensesfieldname
    let cntofSelect := count(yourSelect)
    slice(yourSelect,cntofSelect-5,cntofSelect)
    

    I don’t know if you had sorted your select, but if you didn’t then you can add the order by command to sort by the appropriate fieldname.

    Then we get a count of records.

    Then we take the last 5.

      • Créateur de bien-être
      • Sebastien_Guillet
      • 1 yr ago
      • Reported - view

      Fred Thank you very much, it works.

    • Créateur de bien-être
    • Sebastien_Guillet
    • 1 yr ago
    • Reported - view

    Fred I was able to get your code to work however, I forgot to include a condition. Here is the code I am using:

    let yourSelect := ((select Comptes)['Total facturé'] order by 'Total facturé');
    let cntofSelect := count(yourSelect);
    slice(yourSelect, cntofSelect - 5, cntofSelect)
    

    I would have to condition the code like this:

    let filterStart := 'Début du filtre';
    let filterEnd := 'Fin du filtre';
    let yourSelect := (select Comptes)[date('Première interaction') >= filterStart and
            date('Première interaction') <= filterEnd];
    (select Comptes)['Total facturé'] order by 'Total facturé';
    let cntofSelect := count(yourSelect);
    slice(yourSelect, cntofSelect - 5, cntofSelect)
    

    I can't get the sorting function to work, which is essential in this specific case : (select Comptes)['Total facturé'] order by 'Total facturé'

      • Fred
      • 1 yr ago
      • Reported - view

      Sébastien Guillet try:

      let filterStart := 'Début du filtre';
      let filterEnd := 'Fin du filtre';
      let yourSelect := (select Comptes)[date('Première interaction') >= filterStart and
              date('Première interaction' <= filterEnd and 'Total facturé')] order by 'Total facturé';
      let cntofSelect := count(yourSelect);
      slice(yourSelect, cntofSelect - 5, cntofSelect)
      

      Just keep adding your filtering requirements in between the [ ].

      I learned recently that the difference between using where and [ ] in a select is that the where only sends over the records that match your filters. If you use the [ ] then it copies over the whole table then filters. Not a big deal with small tables, but could be a big issue once your tables become bigger.

      • Créateur de bien-être
      • Sebastien_Guillet
      • 1 yr ago
      • Reported - view

      Fred Following your advice to use the where function, I adapted the code and it works which I post below. Thank you again.

      let filterStart := 'Début du filtre';
      let filterEnd := 'Fin du filtre';
      let yourSelect := ((select Comptes
              where date('Première interaction') >= filterStart and
                  date('Première interaction') <= filterEnd and
              'Total facturé') order by 'Total facturé');
      let cntofSelect := count(yourSelect);
      slice(yourSelect, cntofSelect - 5, cntofSelect)
      

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 5Replies
  • 98Views
  • 2 Following