Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

Multi-select prompt that would work with an SQL Exists condition

  • 1.  Multi-select prompt that would work with an SQL Exists condition

    Posted Wed January 22, 2025 05:02 AM

    Hello experts !

    I was wondering how to do work a multi select (checkbox) prompt with a SQL code that need to use a EXIST condition ?

    Any information would be appreciated.

    Thank you for any help 



    ------------------------------
    German Rodriguez
    ------------------------------


  • 2.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Thu January 23, 2025 05:03 AM

    I'm not sure Cognos supports the EXISTS clause. Are you using it right now? Show me your current filter and I can help get it set up with a multiselect prompt. 



    ------------------------------
    Paul Mendelson Product Manager
    Product Manager
    PMsquare
    ------------------------------



  • 3.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Fri January 24, 2025 10:38 AM

    Thank you Paul for your answer.

    I'll try to explain it simple. 
    Imagine you have 3 tables PEOPLE, FRUITS, ALLERGIES.
    I would like to do a raport with a multi select (checkbox) prompt where users can select who has allergies to many fruits at the same time ( exemple who cannot eat apples, no pears, no cherries) when using multi select (checkbox) prompts it works like an IN logique while I need and AND logic. I would prefer to do this with only one prompt and not with as much prompts as fruits I have in my table
    Hope it's clear and thank you again for any tips. 

    Best regards,

    German



    ------------------------------
    German Rodriguez
    ------------------------------



  • 4.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Fri January 24, 2025 11:27 AM

    Hi German,

    This is a common ask to build a complex filters on dynamic selections of the columns with multi selects for multiple dimensions or columns.

    You can only achieve by logical prompts sequencing or by deriving required SQL using javascripts, macro and prompt combinations.

    One of the example that our development team build as Utility called "FlexiPrompts" a java extension for cognos. See the video attached for your ref,

    Enhancing Cognos Dashboards: Real-time Dynamic Search with FlexiPrompts

    Blog remove preview
    Enhancing Cognos Dashboards: Real-time Dynamic Search with FlexiPrompts
    Explore how FlexiPrompts brings real-time dynamic search to Cognos dashboards, empowering your analytics for more informed decisions. Learn more in our blog.
    View this on Blog >

    Let us know if this works for your need we can implement it.



    ------------------------------
    Jacky Patel
    Director Analytics Solutions
    Veracitiz Solutions Pvt Ltd
    Navi Mumbai, INDIA
    +91 91677 55646
    jpatel@veracitiz.com
    ------------------------------



  • 5.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Mon January 27, 2025 02:33 AM

    Hi Jacky,

    Thank you for your answer.

    What I see in the video is for dahsboards only and I would need the same for reports. By the way, we need to do this with the options included in the set of ICAS tools, but thank you for your offering.

    Best regards  



    ------------------------------
    German Rodriguez
    ------------------------------



  • 6.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Tue January 28, 2025 01:34 AM

    Hi German,

    Thank you for the inputs, 

    in the video before clicking on the dashboard button all the views are build on the Cognos report studio page only. entire filter, prompt selections are configured on RS and then only Dashboard click is to view the Dashboard on the filtered output.

    Can you explain what you want with this? >>> by the way, we need to do this with the options included in the set of ICAS tools.



    ------------------------------
    Jacky Patel
    Director Analytics Solutions
    Veracitiz Solutions Pvt Ltd
    Navi Mumbai
    +919167755646
    ------------------------------



  • 7.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Tue January 28, 2025 06:05 AM

    Just to be clear, you're looking to do a filter that would return a list of all people who are allergic to the exact list selected, or who have ANY of the allergies listed?

    so let's say Alice is allergic to apples, Bob is allergic apples and bananas, and Charlie is allergic to apples, bananas, and cherries. If you select apples, bananas, and cherries who should we see? Based on my understanding we should only see Charlie - is that correct?



    ------------------------------
    Paul Mendelson Product Manager
    Product Manager
    PMsquare
    ------------------------------



  • 8.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Tue January 28, 2025 07:00 AM
      |   view attached

    I've made a really quick model. Fruit.xlsx has the data, AllergiesModel.json is the model, and report.txt is the report. 

    The filter shows everyone who is allergic to apples:





    And now it shows everyone who is allergic to both Apples and Bananas:



    ------------------------------
    Paul Mendelson Product Manager
    Product Manager
    PMsquare
    ------------------------------

    Attachment(s)

    zip
    Fruit.zip   11 KB 1 version


  • 9.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Wed January 29, 2025 01:46 AM
    Edited by German Rodriguez Wed January 29, 2025 02:21 AM

    Hi Paul,

    Thank you very for your help. Yes. It is correct. 

    Could you please provide me a deployment file or a short explains of the model because with my French Keyboard  in WIN11 the "CTRL + / + Q" option is not working anymore.

    Thank you very much for your time and help



    ------------------------------
    German Rodriguez
    ------------------------------



  • 10.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Thu January 30, 2025 02:22 PM

    Hello I'm Ramzi and I'm seeking for interesting people in Quantum computing,  I wanna be member of them



    ------------------------------
    Maghzaoui Ramzi
    ------------------------------



  • 11.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Wed January 29, 2025 03:19 AM
    Edited by Marc Reed Wed January 29, 2025 04:24 AM

    I think @Paul Mendelson and I have come up with the same solution to this.  

    The IN clause will return people who have any of the fruit selected. So if your prompt answer was 'Apple';'Banana';'Cherry' your report would return people who have any of these alergies.

    The trick is to count the number of allergies that were returned for each person and see if it equals the number of fruit selected in the prompt.

    For example, lets say filtering on the above fruit returns the following list using the IN filter

    1. Marc Banana
    2. Marc Apple
    3. Marc Cherry
    4. Paul Apple
    5. Paul Banana
    6. German Apple

    If we count the number of allergies for each person we see

    1. Marc = 3
    2. Paul = 2
    3. German =1 

    Our prompt contained 3 fruit, so with another filter of counting the alergies per person = the number of values in the prompt,  the list will now only return Marc.

    Counting the number of answers in the prompt parameter is the messy bit.

    I think an additional filter looking something like:

    count( distinct [Fruit] for [Person) =
    #
    length( 
       join( 
          '',  
          substr( 
             split(';', promptmany( 'Fruit','integer') )
             , 0, 1 
           ) 
       )
    )
    #

    Explaining the filter; the first bit is easy - count the distinct number of fruit for each person. The bit between the #'s is the macro that is counting the number of prompt answers. It's not obvious but here goes...
    (this code is very similar to Paul's but I have a slightly simpler version)

    PromptMany will be the prompt answer, as its promptmany and an integer, this will be a semicolon separated list - for example 1234;3456;987

    We split this into an array of elements based using the semicolon to split. this give an array with three elements.

    For each element in the array we do a substring and just get the first character. we will now have an array of three elements, each element will just be the first chararacter.

    I then JOIN all the elements in the array back into a single string. I then use LENGTH to determine the length of the string - which will be the number of prompt answers.

    If you don't like the macro way of counting the number of answers in the prompt then you can do something similar in sql - depending on your flavour of sql.

    length( replace(   #sq(  promptmany( 'Fruit','integer') ) # || ';', ';'  , 'XX' ) )
    -
    length(  #sq(  promptmany( 'Fruit','integer') ) # || ';'  )

    The way this works is again using the promptmany semicolon separated list. For example, if the user answered with a single valie the promptmany could return 999, if they answered with multiple values it would return 999;123;1;3.  

    I use the macro SQ() function to quote this with single quuotes, in effect turning it into a string. such as '999' or '999;123;1;3'.

    I append this string with a semicolon - '999;' or '999;123;1;3'.

    I then replace the semicolon with XX - in effect replacing 1 character with two. I can then compare the lengths of the strings - the one with the semicolons, and the one containing XX. The difference will be he number of parameters.



    ------------------------------
    Marc Reed
    Reporting Lead
    ------------------------------



  • 12.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Wed January 29, 2025 03:48 AM

    Hi Marc,

    Thank you for your help and all the explanations for this good idea.

    I'll try to do that in my report and I'll come back as soon as possible.

    Best regards,

    German



    ------------------------------
    German Rodriguez
    ------------------------------



  • 13.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Thu January 30, 2025 03:45 AM

    @German Rodriguez I was thinking there must be a simpler way to count the number of values returned by the prompt. I came up with this:

    #
    let vFruit = promptmany( 'pFruit', 'integer' ) + ';' ;
    length( join( ';;',  split( ';', vFruit) ) ) + ' - ' + length( vFruit )
    #

    This works similar to the sql method, but in macro code. It's a bit simpler as we can use a variable to park to the prompt parameters. 

    pFruit will be a semicolon separated list.
    First, add a trailing semicolon as the last value will not have a semicolon after it.
    Then replace every semicolon with two semicolons.
    Then compare the lengths of the two strings.
    For example
    pFruit = 1;2;3
    becomes
    pFruit = 1;2;3; with a length of 6
    becomes
    pFruit = 1;;2;;3;; with a length of 9
    compare the length of the two strings 
    We then create the expression '9 - 6' to be evaluated by the sql engine as macros dont do maths.
    I use the split/join functions to do a find and replace.

    Wonder if anyone else can come up with a more efficient way of counting values in a parameter?



    ------------------------------
    Marc Reed
    Reporting Lead
    ------------------------------



  • 14.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Thu January 30, 2025 04:17 AM
      |   view attached

    Example report against the standard Go Sales.



    ------------------------------
    Marc Reed
    Reporting Lead
    ------------------------------

    Attachment(s)

    txt
    SampleReportIn.txt   6 KB 1 version


  • 15.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Thu January 30, 2025 04:30 AM

    #length(
      join('',
        substr(split(';',promptmany('Fruit','integer')),0,1)
      )
    )#

    Split the prompt many into an array of values. 

    [123,234,345,456,567]

    substring each element to a single character

    [1,2,3,4,5]

    join into a string with no separator

    12345

    count the characters

    5

    This works with strings, muns, integers, and so on. multiselect intervals are a bit weird and I'd have to experiment a bit. You can use a case statement to handle optional parameters that are unpopulated:

    #
    let param = promptmany('Fruit','integer','NA');
    let arr = split(';',param);
     
    case param 
      when 'NA' then sq('No values selected!')
    else sq(length(
      join('',
        substr(arr,0,1)
      ) 
    )+ ' values selected')
    end#


    ------------------------------
    Paul Mendelson Product Manager
    Product Manager
    PMsquare
    ------------------------------



  • 16.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Thu January 30, 2025 04:45 AM

    First method is the one I posted initially and by using reporting optional params setting we don't need to add that complexity into the macro. See example report.

    Challenge is still on to find the smallest bit of code to count the values in a parameter!



    ------------------------------
    Marc Reed
    Reporting Lead
    ------------------------------



  • 17.  RE: Multi-select prompt that would work with an SQL Exists condition

    Posted Fri January 31, 2025 02:46 AM

    Hello Marc & Paul,

    Thank you very very much for your help. It works like a charm !! :) It does exactly what I need.

    Best regards.

    Geman



    ------------------------------
    German Rodriguez
    ------------------------------