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

SQL DATE Hierarchy

I understand that pulling in dates from SQL messes with the date hierarchy, so I imported my date table (calendarlookup) because we have a funky Fiscal Year and created a date hierarchy using that date table using these formulas:

DateYear = YEAR('calendarlookup'[DATE])
DateMonth = MONTH('calendarlookup'[DATE])
DateDay = DAY('calendarlookup'[DATE])

 

I'm using a Slicer / List with the Month and Day as the fields as the visuals will be the totals for each Year and this way they can choose the specific months that they want to compare across those years.

 

I wanted to use the Name of the month, so I tried 
DateMonthName = FORMAT('calendarlookup'[date], "MMM") - but that sorts alphabetically rather than by the date.  

 

I did the "sort by column" option and chose the unique date field, but that didn't help either.

 

Any help on getting the list to look like this (which worked when I brought in the data through Excel)

dpeacock_1-1626392175579.png

 

Instead of this (date brought in through SQL server)

dpeacock_0-1626392153945.png

would be greatly appreciated!

 

Thanks much!

Dawn

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can try to sort Month column by MonthNum column.

Here's the example.

MonthNum = MONTH([Date])
Month = FORMAT([Date],"mmm")

10.png11.png

And hierarchy worked.

12.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can try to sort Month column by MonthNum column.

Here's the example.

MonthNum = MONTH([Date])
Month = FORMAT([Date],"mmm")

10.png11.png

And hierarchy worked.

12.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AllisonKennedy
Super User
Super User

@Anonymous  You should do all of this in the date table, and your sort by column must be on a month number, not unique date. Ie if you have 12 Month names you must sort by a column that has 12 month numbers (the Date column has 365 unique values in a year instead of 12) 

Here's a M script for a date table if you don't have one already; 

https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Thank you for the info!  That works on my other reports that don't pull in from SQL but not on the SQL ones.  The field is formatted in SQL as date/time and I change it to date in the Query Editor once it's been imported. 

 

I have a date table that has our very weird FY dates that I use with other reports that works well, but - again - just can't make it do it's thing here.  Once I link the date table to the SQL imported table, it won't give me the hierarchy, so I created the hierarchy manually thinking that might help, but it didn't.

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.