0

Search with Multiple Choice problem

Fred

I use these Formula and work but the problem is I have only 3 items in the table Tipo de Documento and need to use aleatory case number. I try one by one I'm lucky to find the case number, and if I insert another Tipo de Documento have problems.

switch number(Busqueda) do
case 1:
    (select Documentos where 'Tipo Documentos'.Clase = "Plano" and 'Ganado REAL' = null)
case 4:
    (select Documentos where 'Tipo Documentos'.Clase = "Actividad" and 'Ganado REAL' = null)
case 8:
    (select Documentos where 'Tipo Documentos'.Clase = "Documento" and 'Ganado REAL' = null)
end

26 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    Hi Rafael -

    Are you saying that you should have found more than 4 records when searching:

    'Tipo Documentos'.Clase = "Plano" and 'Ganado REAL' = null

    When you say:

    I try one by one I'm lucky to find the case number

     Do you mean you don't know how to find the choice numbers for the field Clase?

    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    Fred

    The formula give me the good result.

    The problems is with the case number, the first time don´t work with

    case 1

    case 2

    case 3 

    Then I try to find what case will work and work the case 1 , case 4 and case 8 and I case only 3 Tipo de Documentos, and if insert a new Tipo de Documentos de case 4 not work.

    I don´t know how to find the case the choice number 

    • Fred
    • 1 yr ago
    • Reported - view

    Ok, so you are switching on the field Busqueda. Is that a simple choice field? or a Dynamic choice field?

    If it is a simple choice, then the choice numbers are there when you edit the choice field.

    If it is a dynamic choice, then the numbers are the record Id in the table.

    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    Fred

    Is a Multiple Choice Dynamics, in the Table the id number are in the picture, but with these numbers the case don´t work.

    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    Fred

    I send you again the DB.

    The table Tipo de Documentos is the Table with the 3 kind of documents maybe there will be more.

    In the Table Documentos in the Tab Busqueda you will find the Multiple Choice. 

    • Fred
    • 1 yr ago
    • Reported - view

    I was wrong about the dynamic multichoice field. When you use number() it does not give the record Id number when you select multiple choices.

    FYI, if you use numbers (ending with "s") then you an array of the record Ids.

    Here is one solution but only works if you have a 3, maybe 4, choices. The combinations grow to large when there are more choices. Maybe someone smarter than me can figure out a solution that can handle a larger choice selection.

    let x := text(Busqueda)
    let check1 := if x like "Plano" then 1 end;
    let check2 := if x like "Actividad" then 2 end;
    let check3 := if x like "Documento" then 4 end;
    let mode := check1 + check2 + check3;
    switch mode do
    case 1:
    (select Documentos where 'Tipo Documentos'.Clase = "Plano" and 'Ganado REAL' = null)
    case 2:
    (select Documentos where 'Tipo Documentos'.Clase = "Actividad" and 'Ganado REAL' = null)
    case 3:
    (select Documentos where 'Tipo Documentos'.Clase = "Actividad" and 'Tipo Documentos'.Clase = "Plano" and 'Ganado REAL' = null)
    case 4:
    (select Documentos where 'Tipo Documentos'.Clase = "Documento" and 'Ganado REAL' = null)
    case 5:
    you can fill in here
    case 7:
    you can fill in here
    end
    
    

    Since you are using a dynamic multi choice (dMC) we have to convert the information into usable data. Again, this is one solution and not very dynamic 😄. So line 1 takes Busqueda and turns it into text. Lines 2-4 creates a variable that checks for each type and assigns a number value.

    Line 5, adds up the newly created variables into a new variable so we can use the switch function depending on their sum.

    Line 6 - 19 is where all the magic happens. I think you can figure out the relationship between the case and the search you need to do.

    I hope this helps and maybe someone will come up with a solution that scales better.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Fred 

      Works Excelent again thanks a lot. 👋

    • Alain_Fontaine
    • 1 yr ago
    • Reported - view

    I had a look at your database, and devised the following formula to fill the view:

    let b := numbers(Busqueda);
    (select Documentos)[(
                let t := number('Tipo Documentos');
                cnt(b[= t])
            ) and 'Ganado REAL' = null]
    

    This formula works without the need to enumerate the various choices, and without making reference to the names of the document types. One can thus add or remove records in the "Tipo Documentos" table, or change the values in the "Clase" field without needing to change the formula.

      • Fred
      • 1 yr ago
      • Reported - view

      Alain Fontaine I knew someone would come up with something more flexible.

      If you have time, can you help me wrap my head around using the cnt function to do a selection.

      You wrote:

      (select Documentos)[(
                  let t := number('Tipo Documentos');
                  cnt(b[= t])
              ) and 'Ganado REAL' = null]
      

      So on line 3, it says to count the array of numbers from Busqueda that equal the number from Tipo Documentos from the Documentos table. If that is correct then what I don't understand is how you can just count something and it finds the selected records. Don't you have to say if the count is greater than 0 or is that implied.

      • Alain_Fontaine
      • 1 yr ago
      • Reported - view

      Fred The magic lies in the expression: b[=t].  Its effect is to filter the array "b", keeping only the elements that satisfy the condition inside the square brackets, in this case, those that are equal to "t". So, if the array contains a number equal to "t", it is reduced to that one element; if not, to zero elements. One just has to count the remaining elements to determine if a value equal to "t" was present in the original array.

      With due recognition to  for pointing out that the square bracket notation can be used to filter arrays.

      • Fred
      • 1 yr ago
      • Reported - view

      Alain Fontaine Thanks for the update. Maybe one day my little brain will absorb this new way of thinking.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Alain Fontaine 

      Hi Alain do you think this Formula can be optimize. I need only with 'Ganado Real' = null but show me  'Ganado Real' with values

      let myFrom := 'Desde Fecha';
      let myTo := 'Fecha Corte';
      switch number(Fechas) do
      case 1:
          (select DOCUMENTOS where 'Ganado REAL' = null or FechaR1 >= myFrom and FechaR1 <= myTo)
      case 2:
          (select DOCUMENTOS where 'Ganado REAL' = null or FechaR2 >= myFrom and FechaR2 <= myTo)
      case 3:
          (select DOCUMENTOS where 'Ganado REAL' = null or FechaR3 >= myFrom and FechaR3 <= myTo)
      case 4:
          (select DOCUMENTOS where 'Ganado REAL' = null or FechaR4 >= myFrom and FechaR4 <= myTo)
      case 5:
          (select DOCUMENTOS where 'Ganado REAL' = null or FechaR5 >= myFrom and FechaR5 <= myTo)
      end

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Alain Fontaine

      • Alain_Fontaine
      • 1 yr ago
      • Reported - view

      Rafael If you want to see the records of the table "Documentos" whose selected date falls in the stated interval AND where the field "Ganado REAL" is  "null", you should specify the "and" operator instead of the "or" operator.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Alain Fontaine Hi Alan with the and don't work don't give any result.

      • Alain_Fontaine
      • 1 yr ago
      • Reported - view

      Rafael In the "No Emitidos" view, there is a filter on the "FechaR1" column. Only the lines where this field is empty would be displayed, in addition to the conditions set in the formula.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Alain Fontaine Yes is I Filter works. Ok thanks

    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    Alain Fontaine

    Fred

    I really appreciate your help without this help this would not have come out.

    Great support I hope this BD that I have shared helps other new ones.

    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    Fred

    Fred why I can't view the table in this table ? 

      • Fred
      • 1 yr ago
      • Reported - view

      Rafael What table are you talking about? I see a view called Disciplinas in a form called Fechacorte in a table called Fechacorte.

    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    I can,t see on FECHACORTE the Table with the fields.

    Some Enable and Disable the  > ( near the name table)  for view the table. 

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      In the Fecha Corte I can't see the arrow like in HITOS

      How enable and disable that.

      • Fred
      • 1 yr ago
      • Reported - view

      If this is from the DB that I modified then I made FechaCorte into a Dashboard so there is only 1 view and it is a form view. In a dashboard there is no need for a table view so I got rid of it.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Fred ok and how do you do that

    • Fred
    • 1 yr ago
    • Reported - view

    1) click on the + and type in a name for the view and select form

    2) ctrl+click on the all view and select Delete View

    now you only have 1 view.

    Also dashboards only have 1 record so there is no need for a table view.

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 26Replies
  • 223Views
  • 3 Following