LoginSignup
1
3

More than 3 years have passed since last update.

Power BIで日付テーブルを作る

Last updated at Posted at 2019-12-25

1. テーブルを作る

左タブ [データ] > 上部タブ [モデリング] > [新しいテーブル] > テキストボックスに下記のDAX関数をコピペ

Calendar = 
ADDCOLUMNS (
CALENDAR (DATE(2000,1,1), DATE(2025,12,31)),
"DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
"Year", YEAR ( [Date] ),
"Monthnumber", FORMAT ( [Date], "MM" ),
"YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
"MonthNameShort", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "ddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )
)

2. 日付テーブルとしてマークする

[日付テーブルとしてマークする] > [Date]を選択

3. Calendarテーブルと紐づけたいテーブルにリレーション設定用の列を作成する

Date列同士だと、時刻まで加味されてしまう。今回は日単位でリレーションを設定したいので、リレーション設定用のカラムを作る。今回はDateAsIntegerを使う。

左タブ [データ] > 上部タブ[モデリング] > [新しい列] > 下記DAX関数を追加

DateAsInteger = FORMAT ( [Date列], "YYYYMMDD" )

3. リレーションを設定する

左タブ [モデル] > 接続したいテーブルに[DateAsInteger]フィールドをドラッグアンドドロップ

image.png

参考

How to create a date table in Power BI in 2 simple steps - Kohera
Lesson 4: Create Relationships | Microsoft Docs
Re: Date Table Data Mixup - Microsoft Power BI Community

1
3
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
3