0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Power BIで前年差異や累積の計算を行う

0
Last updated at Posted at 2026-10-06

一連の投稿で、
「Cognos Analytics をエンドユーザーの方に自己学習して頂くためのサイト」 (Cognos Analytics レポート グラフとリストを自在に配置する)
内の手順をPower BIで再現してみます。
今回は上記サイトのうち「Cognos Analytics レポートで前年差異や累積の計算を行う」という手順を行います。

※Cognosのように「画面上のリストの並び順」を自動参照する仕組みとは異なり、Power BIでは「何を基準に順序(年など)を定義するか」を式の中で明確に指定する必要があります。

  1. 準備:メジャーの作成方法

キャンバス上にビジュアルを配置します。

画面右側の「視覚化」ペインから「テーブル」(または「マトリックス」)ビジュアルを選択してキャンバスに配置します。

作成した Sales テーブルから、Product, Year, Units Soldを「列」にドラッグ&ドロップします。

image.png

右側の「データ」ペインで financials テーブルを右クリック > 「新しいメジャー」 を選択します。
image.png

画面上部に数式バーが表示されるので、以下のDAX式を入力してEnterキーを押します。

前年差異.dax
前年差異 = 
VAR CurrentProduct = SELECTEDVALUE('financials'[Product])
VAR CurrentYear = SELECTEDVALUE('financials'[Year])
VAR PreviousYearQuantity = 
    CALCULATE(
        SUM('financials'[Units Sold]),
        REMOVEFILTERS('financials'[Year]),
        'financials'[Year] = CurrentYear - 1,
        'financials'[Product] = CurrentProduct
    )
VAR CurrentQuantity = SUM('financials'[Units Sold])
RETURN
    IF(
        ISBLANK(PreviousYearQuantity),
        BLANK(),
        CurrentQuantity - PreviousYearQuantity
    )

image.png

再度「新しいメジャー」をクリックし、2つ目の式を登録します。

累積合計.dax
累積合計 = 
VAR CurrentProduct = SELECTEDVALUE('financials'[Product])
VAR CurrentYear = SELECTEDVALUE('financials'[Year])
RETURN
    CALCULATE(
        SUM('financials'[Units Sold]),
        REMOVEFILTERS('financials'),
        'financials'[Product] < CurrentProduct
            || ('financials'[Product] = CurrentProduct && 'financials'[Year] <= CurrentYear)
    )

作成した前年差異、累積合計メジャーを「データ」から「列」へドラッグ&ドロップ。
image.png

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?