3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Last updated at Posted at 2021-01-17

以下のYoutubeビデオで、カレンダーテーブルの作成について詳しく紹介されていましたので、カレンダーテーブルを作ったことがない方はぜひご覧ください。

 また、この記事より @ishiayaya さんの記事の方が役に立ちます。

DateTable = 
// 日付を指定するか、CALENDARAUTOに任せるか
// VAR BaseCalendar = CALENDAR( DATE(2016,1,1), DATE(2018,12,31) )
VAR BaseCalendar = CALENDARAUTO()
RETURN
    GENERATE(
        BaseCalendar,
        VAR BaseDate = [Date]
        VAR DayNumber = DAY( basedate )
        VAR YearDate = YEAR( BaseDate )
        VAR MonthNumber = MONTH( BaseDate )
        VAR YearMonthName = FORMAT( BaseDate, "yyyymm" )
        VAR YearMonthNumber = YearDate * 12 + MonthNumber - 1
        VAR YearMonthDayName = FORMAT( BaseDate, "yyyymmdd" )
        VAR DayOfWeekName = FORMAT( BaseDate, "aaa", "ja-JP" )
        // // 月曜スタート
        // VAR DayOfWeekNumber = WEEKDAY( BaseDate, 3 )
        // VAR StartOfWeek = BaseDate - DayOfWeekNumber
        // 日曜スタート
        VAR DayOfWeekNumber = WEEKDAY( BaseDate, 1 )
        VAR StartOfWeek = BaseDate - DayOfWeekNumber - 1
        //
        VAR YearWeekNumber = WEEKNUM( BaseDate )
        VAR EndDate = EOMONTH( BaseDate, 0 )
        VAR DaysOfMonth = DATEDIFF( BaseDate, EDATE( BaseDate , 1 ), DAY )
        RETURN ROW (
            // English
            "Year", YearDate,
            "Month", MonthNumber,
            "Day", DayNumber,
            "YearMonth_Number", YearMonthNumber,
            "YearMonth", YearMonthName,
            "YearMonthDay", YearMonthDayName,
            "Week", DayOfWeekName,
            "WeekNumber", DayOfWeekNumber,
            "YearWeekNumber", YearWeekNumber,
            "WeekStartDate", StartOfWeek,
            "EndOfMonth", EndDate,
            "Days of Month", DaysOfMonth
            // // Japanese
            // "年", YearDate,
            // "月", MonthNumber,
            // "日", DayNumber,
            // "年月_番号", YearMonthNumber,
            // "年月", YearMonthName,
            // "年月日", YearMonthDayName,
            // "曜日", DayOfWeekName,
            // "曜日_番号", DayOfWeekNumber,
            // "年曜日_番号", YearWeekNumber,
            // "週開始日", StartOfWeek,
            // "月末日", EndDate,
            // "月日数", DaysOfMonth
        )
    )

image.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?