0

nach Anzahl Sortieren

Hallo zusammen,

ich steh mal wieder komplett auf dem Schlauch...

Folgender Code tut was er soll, ich hätte jetzt nur gerne, das die Liste nach Anzahl der Verwendung der Instrumente sortiert wird. (absteigend)

let my := this;
let myArray := unique(Setlist.'Stück'.Stimmen.Spur.Instrument);
let myArray2 := for ii in myArray do
        cnt(Liste.'Stück'.Stimmen.Spur[Instrument = ii].Instrument) + "x " +
        record(Instrument,ii).Bezeichnung
    end;
join(myArray2, "
")

Kurze Erklärung:
ich befinde mich in einer Setlist.
In der Liste sind die verknüpften Stücke. Ein Stück besteht aus Stimmen, in einer Stimme können mehrere Spuren sein. Eine Spur ist dann mit einem Instrument verknüpft.
Die Anzahl wird mir korrekt vor der Instrumentenbezeichnung angezeigt, aber eben nicht sortiert.

Order by funktioniert in Zeile zwei irgendwie nicht...

Danke schon mal im Voraus!

VG Johannes

10 Antworten

null
    • + Maßanzug statt Massenware +
    • RonaldP
    • vor 10 Tagen
    • Gemeldet - anzeigen

    Moin ,

    versuche es mal mit sort()
    https://forum.ninox.de/t/35yh5j5/sort

    Vg Ronald

      • john_eans
      • vor 9 Tagen
      • Gemeldet - anzeigen

       
      So hatte ich auch erst gedacht, gibt aber z.B. aber Probleme bei 10x Instrument 1 und 9x Instrument 2
      Die Lösung von Fred ist spitze. Ich hab zwar etwas gebraucht, aber das funktioniert einwandfrei und lässt ja noch viel mehr zu.

    • Fred
    • vor 10 Tagen
    • Gemeldet - anzeigen

    You can use JSON to create a new "table" that has the count in it then you can sort by the new "count" field.

    Here is an example:

    You can take this code:

    Formula 3
    (select Table1).{
        recID: Id,
        countOf: count(TableA)
    }
    
    then you can add the order by
    
    Formula 4
    (select Table1).{
        recID: Id,
        countOf: count(TableA)
    } order by -number(countOf)
    

    You can see that Formula 4 adds the order by command. As JSON data is typed as any, we have to use the number() command to convert the data in 'countOf' into a number. Then we use the simple '-' in front of number to tell Ninox to do descending. 

    • Fred
    • vor 10 Tagen
    • Gemeldet - anzeigen

    I think this will work with your code:

    let myArray := unique(Setlist.'Stück'.Stimmen.Spur.Instrument);
    let myJSON := for ii in myArray do
        {
            count: cnt(Liste.'Stück'.Stimmen.Spur[Instrument = ii].Instrument)
            txt: cnt(Liste.'Stück'.Stimmen.Spur[Instrument = ii].Instrument) + "x " + record(Instrument,ii).Bezeichnung
        }
        end;
    concat((myJSON order by -number(count)).txt)
    
      • john_eans
      • vor 9 Tagen
      • Gemeldet - anzeigen

       

      Hi Fred,

      thank you very much for your detailed reply — that works perfectly!
      I really appreciate the way you explained the logic behind the JSON approach.

      The sorting with the JSON approach isn’t the standard way, but it opens up so many possibilities.
      It will definitely help me with other problems as well and will probably simplify many of my apps in the long run.

      Thanks again for sharing this idea!

      • Fred
      • vor 8 Tagen
      • Gemeldet - anzeigen

       Glad it worked out for you. When you have a moment please marked the post "answered".

      • Rafael_Sanchis
      • vor 8 Tagen
      • Gemeldet - anzeigen

       

      let myArray := unique((select 'Planning Data').a_Projects);
      let myJSON := for ii in myArray do
              {
                  count: cnt(unique((select 'Planning Data')[a_Projects = ii].'a_Employee Name')),
                  txt: cnt(unique((select 'Planning Data')[a_Projects = ii].'a_Employee Name')) + " " +
                  record(Projects,ii).'Project Name'
              }
          end;
      concat((myJSON order by -number(count)).txt, " | ")
      

      Hi Fred a_Projects is a relationfield  and a_Employee Name to, both 1:N and work perfect give me how many employees per proyects 

    • Rafael_Sanchis
    • vor 7 Tagen
    • Gemeldet - anzeigen

    better visualization of the information, witn the same script.

      • john_eans
      • vor 7 Tagen
      • Gemeldet - anzeigen

       

      Could you share the code for the visualization? It looks really cool. 🙂

      • Rafael_Sanchis
      • vor 7 Tagen
      • Gemeldet - anzeigen
      let myArray := unique((select 'Planning Data').a_Projects);
      let allEmployees := unique((select 'Planning Data').'a_Employee Name');
      let totalCount := cnt(allEmployees);
      let htmlCards := "";
      for ii in myArray do
          let empList := unique((select 'Planning Data')[a_Projects = ii].'a_Employee Name');
          let empCount := cnt(empList);
          let projName := text(record(Projects,ii).'Project Name');
          let projNameClean := replace(replace(projName, ".", ""), ",", "");
          let percentage := if totalCount > 0 then
                  round(empCount / totalCount * 100, 1)
              else
                  0
              end;
          let orderVal := 1000 - empCount;
          htmlCards := htmlCards + "<div class='project-card' style='order: " + orderVal + "'>" +
              "<div class='project-count'>" +
              empCount +
              "</div>" +
              "<div class='project-name'>" +
              projNameClean +
              "</div>" +
              "<div class='progress-bar'>" +
              "<div class='progress-fill' style='width: " +
              percentage +
              "%'></div>" +
              "</div>" +
              "<div class='percentage-text'>" +
              percentage +
              "% del total</div>" +
              "</div>"
      end;
      html("<div class='dashboard-container'>" +
      "<div class='header'><h3>📊 Staff Allocation by projects</h3></div>" +
      "<div class='projects-grid'>" +
      htmlCards +
      "</div>" +
      "<div class='footer-summary'>👥 Total Employees: <b>" +
      totalCount +
      "</b></div>" +
      "</div>" +
      "<style>
      .dashboard-container {
          font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
          width: 100%;
          margin: 0 auto;
          padding: 10px;
          background: #ffffff;
          border-radius: 10px;
      }
      
      .header {
          text-align: center;
          color: #333;
          margin-bottom: 10px;
      }
      
      .header h3 {
          margin: 0;
          font-size: 16px;
          font-weight: 600;
      }
      
      .projects-grid {
          display: flex;
          flex-wrap: nowrap;
          gap: 8px;
          padding: 5px;
          overflow-x: auto;
      }
      
      .project-card {
          background: #ffffff;
          border: 1px solid #e0e0e0;
          border-radius: 6px;
          padding: 10px;
          box-shadow: 0 1px 3px rgba(0,0,0,0.1);
          transition: transform 0.2s ease, box-shadow 0.2s ease;
          flex: 0 0 auto;
          min-width: 110px;
          max-width: 140px;
      }
      
      .project-card:hover {
          transform: translateY(-2px);
          box-shadow: 0 2px 5px rgba(0,0,0,0.15);
      }
      
      .project-count {
          font-size: 18px;
          font-weight: 700;
          color: #667eea;
          text-align: center;
          margin-bottom: 4px;
      }
      
      .project-name {
          font-size: 11px;
          color: #333;
          text-align: center;
          margin-bottom: 6px;
          min-height: 26px;
          display: flex;
          align-items: center;
          justify-content: center;
          line-height: 1.2;
      }
      
      .progress-bar {
          width: 100%;
          height: 5px;
          background: #f0f0f0;
          border-radius: 3px;
          overflow: hidden;
      }
      
      .progress-fill {
          height: 100%;
          background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
          transition: width 0.5s ease;
      }
      
      .percentage-text {
          font-size: 10px;
          color: #666;
          text-align: center;
          margin-top: 4px;
      }
      
      .footer-summary {
          text-align: left;
          font-size: 13px;
          color: #444;
          margin-top: 8px;
          padding-left: 6px;
          font-weight: 500;
      }
      </style>")
      

Content aside

  • Status Answered
  • vor 7 TagenZuletzt aktiv
  • 10Antworten
  • 79Ansichten
  • 4 Folge bereits