LoginSignup
1
0

More than 5 years have passed since last update.

Cognos レポート 日時単位のデータを午前・午後の単位で集計したい

Posted at

概要

最近質問を受けたので投稿しておきます。
こんな感じに、時刻単位で持っているデータを、その日の午前と午後で集計(平均)して、出力したいという問い合わせでした。
日にち単位だったら簡単そうだけど、特定の範囲(0時~11時⇒午前、12時~23時⇒午後)で括るのって、どうやるのだろうと思った時に思い出して見てください。

003.PNG

実装

以下のようにそれぞれのデータアイテムを実装しています。
case文を使って、条件の範囲でカスタマイズされた集計範囲(午前・午後)を新たに作成し、平均のaverage関数のforで、その集計範囲(午前・午後)を指定する、という感じです。

日付午前午後のデータアイテム
substring(cast([DB2SAMPLE].[TIMESALES].[STIME],char(19)),1,10)
||
case
when substring(cast([DB2SAMPLE].[TIMESALES].[STIME],char(19)),12,2) between 0 and 11 then ' 午前'
when substring(cast([DB2SAMPLE].[TIMESALES].[STIME],char(19)),12,2) between 12 and 23 then ' 午後'
end

平均SALESのデータアイテム
average([DB2SAMPLE].[TIMESALES].[SALES] for [日付午前午後])

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0