Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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 a date hierarchy on my own I can't manage to keep it continuous when drilling down. Instead it automatically switches to Categorical, and then e.g. Forecasting won't work. I've tried all kinds of different ways of creating the hierarchy (e.g. using "Month" = MONTH( [Date] ) or "Month" = FORMAT ( [Date], "MMMM" ) but this doesn't seem to help maintaining a coninuous drill-down. 

 

This image illustrates the difference. The problem occurs on the date hierarchy I've created myself (left) where I can't drill down and keep the X-axis as Continous. But it works on the hierarchy Power BI has created automatically using the date-column (right).

 

date_hierarchy_problem.png

 

1 ACCEPTED SOLUTION
krconrad
Regular Visitor

@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
)
)

 

View solution in original post

9 REPLIES 9
Ghuiles
Advocate IV
Advocate IV

Hi! @krconrad  was right. The SQBI Team published an article on this issue.

Here it is: https://www.sqlbi.com/articles/improving-temporal-line-charts-in-power-bi-with-dax/

As always, it is interesting.

Enjoy.

G.

krconrad
Regular Visitor

@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
)
)

 

I still can't get it working. Can you show me your date hierarchy based on these fields? What am I missing?

L_D_5-1613715475398.png

My date hierarchy created from custom date table:

L_D_2-1613715168406.png

My Year field:

L_D_3-1613715353983.png

My Month field:

L_D_4-1613715402805.png

 

pbit
Regular Visitor

Still no solution to this problem? I’m having the same issue.

kialburg
Frequent Visitor

Was a solution ever found for this issue? I'm having the exact same problem.

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

By my test with creating a date hierarchy, it could be continuous and the Forecasting will work like below.

 

Capture.PNG

 

You should check if the date you created is a Date type or a text type. The feature Forecast is available for line charts only and the x-axis value needs to have a date/time format or be a uniformly increasing whole number.

 

In addition, you could have a reference of this article about forcasting.

 

If you need additional help, please share your data sample so that we could help further investigate on it? You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading.)

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks Cherry
Do I understand you correctly that your “Dateformat” is a manually created hierarchy using Year, Quarter, Month, Day, which are all whole numbers? If you drill down to month-level, will the x-axis then still be continuous?

Was a solution ever found for this?

Anonymous
Not applicable

I have still not found a solution. Have asked everywhere but no one seem to be aware of this, which is highly surprising as any Line Chart might be affected in an undesirable manner if the X-axis can't be set to Continuous.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.