简体   繁体   中英

How to convert SQL statement to equivalent Cognos query calc?

I was building a crosstab like so: 在此处输入图片说明

and need to instead convert into a list. The part that's giving me trouble is converting the grouping of v_IT or BU which feeds down into Act and Direct Cost into 4 separate fields for the list which would be 'IT Act', 'IT Direct Cost', 'BU Act', and BU Direct Cost.' I'm not sure how to make a calculation for these fields using those two data items.

I think the SQL would be something like:

Select Act$ from 'mytable' where v_ITorBU = 'IT'

for the first 'IT Act' data item at least.

v_IT or BU has two values 'IT', and 'BU'.

I tried

Case
When v_ITorBU = 'IT'
then act$
end

but this only gives me the overall act values, not those specifically for IT. I need the specific IT actuals as well as the BU actuals.

Does anyone have any insight on how to make this into Cognos query calculations?

The grouping of v_IT or BU which feeds down into Act and Direct Cost into 4 separate fields for the list which would be 'IT Act', 'IT Direct Cost', 'BU Act', and BU Direct Cost.

Go to the query add data items from the tool box

Create the definition expression, for example this would be for [IT Act]

IF( [v_IT or BU]  = 'IT Act' )Then([Act$])Else(0)

Repeat this process for

  • IT Direct Cost
  • BU Act
  • BU Direct Cost

Also repeat these 4 data items for the cost metric

Remember to check the properties in order to achieve the correct aggregation

Here is the SQL.

select [Budget Category]
, [v_Cost Cat Consolidation]
, sum(case when [v_IT or BU] = 'IT'
        then [Act $]
        else 0
      end) as 'IT Act'
, sum(case when [v_IT or BU] = 'IT'
        then [Direct Cost]
        else 0
      end) as 'IT Direct Cost'
, sum(case when [v_IT or BU] = 'BU'
        then [Act $]
        else 0
      end) as 'BU Act'
, sum(case when [v_IT or BU] = 'BU'
        then [Direct Cost]
        else 0
      end) as 'BU Direct Cost'
from MyTable
where {somefilters}
group by [Budget Category]
, [v_Cost Cat Consolidation]

So a data item expression in Cognos may look like ...

case 
  when [v_IT or BU] = 'IT'
    then [Act $]
  else 0
end

...and you'll want to be sure to use the Total aggregate function on it.

If you have done that and the numbers are not looking right, please add some detail to the problem statement.

This can also be done using the IF-THEN-ELSE methodology proposed by hnoel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM