Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

How to create a Continuous custom Date Hierarchy?

Then automatic date hierarchy created by Power BI is always continuous meaning that if you drill down to month-level in a line chart you can still use e.g. the Forecasting-feature. But when I create ...
  • krconrad's avatar
    6 years ago

    Anonymous and pbit,

     

    I asked a similar question in a comment thread on SQLBI. Link here: http://disq.us/p/28db3dz

    Marco Russo responded with an answer, and it sounds like they're publishing an article about it soon. I'll paste his comment and example below. I hope this helps!

     

    "Power BI uses an internal attribute (data category) that cannot be modified in Power BI.
    You can obtain the same behavior by creating columns as dates and formatting them as you want. We will publish an article about this in a few weeks, the principle is using a calculated table like the one below and then set the custom format of the columns using strings as yyyy (year) and mmm yyyy (month year)..."

     

    Date = 
    VAR FirstFiscalMonth = 7 -- First month of fiscal year
    VAR FirstDayOfWeek = 0 -- 0 = Sunday, 1 = Monday, ...
    VAR FirstYear = -- Customize first year to use
    YEAR ( MIN ( Sales[Order Date] ))
    RETURN
    GENERATE (
    FILTER (
    CALENDARAUTO (),
    YEAR ( [Date] ) >= FirstYear
    ),
    VAR Yr = YEAR ( [Date] ) -- Year Number
    VAR Mn = MONTH ( [Date] ) -- Month Number (1-12)
    VAR Qr = QUARTER ( [Date] ) + 1 -- Quarter Number (1-4)
    VAR MnQ = Mn - 3 * (Qr - 1) -- Month in Quarter (1-3)
    VAR Wd = WEEKDAY ( [Date], 1 ) - 1 -- Week day number (0 = Sunday, 1 = Monday, ...)
    VAR Fyr = -- Fiscal Year Number
    YEAR ( DATE ( Yr, Mn + FirstFiscalMonth - 1, 1 ) )
    VAR Fqr = -- Fiscal Quarter (string)
    FORMAT ( EOMONTH ( [Date], 1 - FirstFiscalMonth ), "\QQ" )
    RETURN ROW (
    "Year", DATE ( Yr, 12, 31 ),
    "Year Quarter", FORMAT ( [Date], "\QQ-YYYY" ),
    "Year Quarter Date", EOMONTH ( [Date], 3 - MnQ ),
    "Quarter", FORMAT ( [Date], "\QQ" ),
    "Year Month", EOMONTH ( [Date], 0 ),
    "Month", DATE ( 1900, MONTH ( [Date] ), 1 ),
    "Day of Week", DATE ( 1900, 1, 7 + Wd + (7 * (Wd < FirstDayOfWeek)) ),
    "Fiscal Year", DATE ( Fyr, FirstFiscalMonth, 1 ) - 1,
    "Fiscal Year Quarter", "F" & Fqr & "-" & Fyr,
    "Fiscal Year Quarter Date", EOMONTH ( [Date], 3 - MnQ ),
    "Fiscal Quarter", "F" & Fqr
    )
    )