0

Is it possible to make a view with a top 10 only?

Let say I have client and purchase. If I wish to make a view with the 10 biggest purchase for exemple, how should I do it? To sort the result, should I use the built in filter or do it in formula? and how do I specify the number of rows to be displayed?

Thanks!

18 replies

null
    • Mconneen
    • 4 yrs ago
    • Reported - view

    WOW.. Never really paid attention that when ordering a select.. it only orders ascending... and the documentation does not list any other option to order descending.. Hmm..   Given that limitaiton..  I am not really happy with this solution . but it works. 

    Following is a dashboard with a view of the top N purchases.    Each Purchase row has a "Rank" number. 

    dashboard

    Here is the code for "Rank" button

    rank

    Here is the code for the view.. 

    view

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, an option for reversing the order would be to assign the group to an array and use rsort()

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Sean.. I thought of that.. but arrays are not multidemisional .. so all I would be sorting is the amounts..  not the records... Or am I missing something? 

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, You are correct about arrays not being multidimensional and I was mainly pointing out the option of using rsort() as a general possibility. Specific to applying rank values based on a field's descending order, you would still need to use the loop as you did and you would have to use 2 parallel arrays; one for Rank and one for Amount. So, it might be more trouble than it's worth.

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Sean... Thanks for confirming.. and I recall a  similar post about "rank".. though a slightly different use case.   As I often say.. I like to walk around the block to go next door.. :) 

    Another design approach could be to create a table that holds the top N values.. and then have a function / trigger on create to see if the purchased value falls within the min / max of that table and insert accordingly ...   Seems like a lot of work when a simple order descending with a counter would do the trick.. :) 

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    Thanks! working fine. I would like to add a selection field and use this selection to filter... It s a composite table where I have my view and the selection, but it seem to not working... in the (select ) it wont take care of my selection...

    what could be the problem?

    thanks

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    Hi, It s working but the only problem is that I need to have a new Rank column for each condition. So if my search criteria changes, I need to add a Rank column to the table...

    I m trying to use a kind of array function to remove some entry according to the 'Top N' field but it s hard to make something works...

    wath do you suggest?

    • Sean
    • 4 yrs ago
    • Reported - view

    @plafontaine44, Can I safely assume your post about idxRemove() is regarding your most recent post in this thread? If so, I think that array function is the wrong tool for the job. You need code to update the rank field and the array function isn't going to do that.

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    ok! because I'm able to get an array with the good value, but I don t know how to fill the view table with it! Your method with the rank value works fine but like I said, if I have a table with some purchased and each item purchased is type_A or Type_B and it could be done at location_A and Location_B and location_C then I would need to have a rank for each condition or so... and it s a lot! (type_A & location_A, type_A & location_B, type_A & location_C, type_B & location_A....) 

    it s a lot just to extract a pre defined number of row in a view...

    do you have any idea to do it simple?

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    With my array I can insert an item() in the criteria but I need to tell the criteria != to all value in my array...that s where the issue came out...

    • Sean
    • 4 yrs ago
    • Reported - view

    Well, you've mentioned a couple of issues not just one. 1) You want to copy array values to your table rank field. 2) You want to sort by a combination of your rank fields. Correct?

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    I want to make a view table that show only a top 5 value or so. But to show only a number of value, I need to filter after filtering. 

    let say: let A := sort((select Achats).total_vente);
    let B := null;
    let j := number_show_1 - 1;
    let x := cnt(A) - 1;
    for i in range(x, j) do
    let B := B + item(A, i);
    B
    end

    this way I get the good value but in an array...I need to make a new filter but I don t know how to use it in filter...

    (select Achats)[total_vente = B]

     

    The 'rank' field is only to be able to filter but like I said if I change any of the filter option, I need a new 'rank' with the new filter... 

    thanks!

    • Sean
    • 4 yrs ago
    • Reported - view

    For what it's worth, I'm pretty sure item(A, i) is returning a string so what you are doing is concatenating items from the array to B which is a string.

     

    It seems to me all you need to do is resequence your Rank field occasionally using the code for the button @Mconneen already gave you.

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    yes that wath I m trying to do for now! I create a main table composite to all other... then I create my view table on the main form with 2 selection field. Here my code inside the selection field 'on update' formula... seems to have an issue with it! I come close but there s something...

    let sort := null;  
    let type_atel := text('Type atelier'); ------> 'selection field 1'
    let sort := if text(Type_produit) = "Accessoire" then  ----> variable with sorting value...
    "total_accessoires"
    else
    if text(Type_produit) = "Epice" then
    "total_aliments"
    else
    "total_vente"
    end
    end;
    let r := cnt(select Achats);
    let a := cnt((select Achats)[text(Atelier.'Type d''Atelier') = text(type_atel)]);
    for p in select Achats do
    p.(Rank := null)----> set all rank to null before to set it...
    end and for p in (select Achats)[text(Atelier.'Type d''Atelier') = text(type_atel)] order by text(sort) do
    p.(Rank := a);
    a := a - 1
    end

     

    can you help me with this? Thanks a lot!

    • plafontaine44
    • 4 yrs ago
    • Reported - view

    seems to be the 'sort' that I m trying to use a variable to order values... should have a way to do it...

    • Sean
    • 4 yrs ago
    • Reported - view

    Umm, I've never seen code where 2 for-loops were combined with "and". Also, you can't sort by proxy and I'm pretty sure you can't filter by proxy either. Meaning, you can't use a variable like "text(sort)" in the "order by" of a select statement.

     

    You will have to test for each condition and then use the literal version of the correct select statement.

    • yinapps.com
    • drew
    • 4 yrs ago
    • Reported - view

    I trust the lack of DESC in an oversight?

    • Jorg
    • 4 yrs ago
    • Reported - view

    Hi Plafontain, 

    may be these functions can help you:

     

    sort(array) - sorts an array in ascending order

    rsort(array) - sorts an array in descending order

     

    Best, Jörg

Content aside

  • 4 yrs agoLast active
  • 18Replies
  • 4833Views