Sort / Order by based on total count
That is even hard to explain. So I do use a dynamic choice box do suggest possible values based on already existing values from that column. I can sort them alphabetically but I would love it if, I could sort them based on the total count. So that my box suggests frequently used values first. I tried a lot like order by or others.
  
let lieferantName := record('ProjektStückliste',number('Lieferant Auswahl')).Lieferant;
let nennweite := record('ProjektStückliste',number('Nennweite Auswahl')).Nennweite;
let kundenName := Projekt.Kundenname;
let stuecke := (select 'ProjektStückliste'
        where Projekt.Kundenname = kundenName and if lieferantName = null then
                    true
                else
                    Lieferant = lieferantName
                end and if nennweite = null then
                true
            else
                Nennweite = nennweite
            end);
let kurzspezifikationen := sort(stuecke.Kurzspezifikation);
for kurzspezifikation in kurzspezifikationen do
    first(stuecke[Kurzspezifikation = kurzspezifikation])
end
Copy
So yeah here instead of the alphabetical sort, I would like to sort based on total count.
5 replies
- 
  You can try: .... let x := for kurzspezifikation in kurzspezifikationen do first(stuecke[Kurzspezifikation = kurzspezifikation]) end x order by KurzspezifikationI’m just modifying the last part since that is the part of the code that is doing the final creation of the record array. Or you can try: let lieferantName := record('ProjektStückliste',number('Lieferant Auswahl')).Lieferant; let nennweite := record('ProjektStückliste',number('Nennweite Auswahl')).Nennweite; let kundenName := Projekt.Kundenname; let stuecke := (select 'ProjektStückliste' where Projekt.Kundenname = kundenName and if lieferantName = null then true else Lieferant = lieferantName end and if nennweite = null then true else Nennweite = nennweite end); stuecke order by Kurzspezifikation
- 
  I managed to solve it with quite complex code. If you see any potential simplification or have a better idea please let me know :). 
 let lieferantName := record('ProjektStückliste',number('Lieferant Auswahl')).Lieferant; let nennweite := record('ProjektStückliste',number('Nennweite Auswahl')).Nennweite; let kundenName := Projekt.Kundenname; let thisRecord := this; let stuecke := (select 'ProjektStückliste' where Projekt.Kundenname = kundenName and if lieferantName = null then true else Lieferant = lieferantName end and if nennweite = null then true else Nennweite = nennweite end and thisRecord != Id); let items := unique(stuecke.Kurzspezifikation); let orderedArr := []; for i from 0 to length(items) do let maxArr := []; let max := ""; let maxCount := 0; for item in items do let tmpCount := count(stuecke[Kurzspezifikation = item]); if tmpCount > maxCount then maxArr := [item]; max := item; maxCount := tmpCount end end; orderedArr := array(orderedArr, maxArr); items := items[!= max] end; for item in orderedArr do first(stuecke[Kurzspezifikation = item]) endwith thisRecord != Id, I want to exclude the current record for the suggestion algorithms. 
- 
  You could perhaps try something like: let lieferantName := record('ProjektStückliste',number('Lieferant Auswahl')).Lieferant; let nennweite := record('ProjektStückliste',number('Nennweite Auswahl')).Nennweite; let kundenName := Projekt.Kundenname; let thisRecord := this; let stuecke := (select 'ProjektStückliste' where Projekt.Kundenname = kundenName and (lieferantName = null or Lieferant = lieferantName) and (nennweite = null or Nennweite = nennweite) and thisRecord != Id); for item in unique(stuecke.Kurzspezifikation) do first(stuecke[Kurzspezifikation = item]) end order by ( let item := Kurzspezifikation; -count(stuecke[Kurzspezifikation = item]) )You did not publish a model of your database, so I could not test this proposal in context. 
Content aside
- Status Answered
- 2 yrs agoLast active
- 5Replies
- 164Views
- 
    4
    Following
    
