COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: hespora on 23 Apr 2025 07:57:19 AM

Title: Crossjoin from prompt input values?
Post by: hespora on 23 Apr 2025 07:57:19 AM
Hi all,


here's what I want to achieve: A query runs against my data source, fetching e.g. three rows of data (three is not fixed, results may vary):
DimValue
A10
B25
C42

I want to crossjoin this to variable input at runtime, e.g. let's say this is the table I want to crossjoin against for one execution (again, number of rows is not fixed):

UserWeight
Jane0.5
Jim0.3
John0.2

So that my final result can be this:

DimUserValue * Weight
AJane5
AJim3
AJohn2
BJane12.5
BJim7.5
BJohn5
CJane21
CJim12.6
CJohn8.4

Now, I know how to achieve this by a) updating an uploaded Excel file with my variable input and refreshing the data module, or b) embed an SQL object in my report definition. Both variants are decent if it's me as an analyst running the report, but are nonviable if the report is for enduser execution.

Is there any way to achieve the same result using prompts to input my weights table at runtime?
Title: Re: Crossjoin from prompt input values?
Post by: dougp on 23 Apr 2025 12:56:40 PM
I'm unclear on the usage requirement.  Are you saying you want the user to tell the report to use arbitrary data for one of the queries?  If so...

This is something we do.  Long ago, I created packages using the "add external data" feature in Cognos 10.2.1 running in IE10, and checking the box to have Cognos ask for the spreadsheet.  But IE10 (and 11) is a security flaw.  That hole was patched, so I don't know how to create such a configuration today in Cognos 11.2.4 and Edge/Chrome.

I have been teaching my users to refresh the spreadsheet, then run the report.  Naturally, that breaks down if you can't trust your basic Excel user to not do typical Excel things, like adding or removing columns, mucking up data types, etc.  So if the report will be used broadly, across many business units and groups who do not own the data and reports, this is not a good solution.

This requirement for one report is keeping me from upgrading a package and from migrating the report to Power BI.  It's a nice feature that I would like to see return.  Please post back if you find a solution.

Title: Re: Crossjoin from prompt input values?
Post by: hespora on 24 Apr 2025 11:05:52 AM
Quote from: dougp on 23 Apr 2025 12:56:40 PMAre you saying you want the user to tell the report to use arbitrary data for one of the queries?
That is exactly what I'm saying! :)

I am... reasonably sure that I can build this (or rather: that this can be built. whether I can do it is a different q) by using macros in a SQL object. It's just rather painstaking and tedious to build; I have no decent way of finding out what exactly a macro turns my input into. I wish there were some kind of "macro sandbox" which lets me fiddle about with several input scenarios and that evaluates macros at runtime *and shows me the result*.
Title: Re: Crossjoin from prompt input values?
Post by: dougp on 24 Apr 2025 04:10:19 PM
I don't think a macro can be created that can be reasonably flexible to handle anticipated user requirements.  As a fun exercise, I worked on exactly that.  Here's what I came up with.  Keep in mind... This falls squarely into the "Why in the world would you do that?" category.



limitations:

It may be possible to mature this a bit more, but I'm thinking some of the limitations of the macro language may be insurmountable.

Note:  This is intended to copy data from Excel and paste into a textbox prompt.  Values are tab-delimited.  In the code below there is a tab in two places.  It may not come across well on this forum.

**Custom SQL - hard coded**

    select *
    from (
      values
        ('', '')
      , ('', '')
    ) q ([customcolumn1], [customcolumn2])

**Custom SQL - with parameter**

    select *
    from (
      values
        #substitute(
        '$',
        ''')',
        substitute(
          '^',
          '(''',
          join(
            '''), (''',
            split(
              ':::',
              join(
                ''',''',
                split(
                  ' ',
                  join(
                    ':::',
                    split(
                      ', ',
                      substr(
                        substr(
                          promptmany('customdata', 'token'),
                          index(
                            promptmany('customdata', 'token'),
                            ', '
                          )
                        ),
                        2
                      )
                    )
                  )
                )
              )
            )
          )
        )
    )#
    ) q (#join(
          ', ',
          substitute(
            '$',
            ']',
            substitute(
              '^',
              '[',
              split(
                ' ',
                substr(
                  promptmany('customdata', 'token'),
                  0,
                  index(
                    promptmany('customdata', 'token'),
                    ', '
                  )
                )
              )
            )
          )
    )#)