Forum Discussion

martinmark's avatar
martinmark
New Member
1 month ago
Solved

Date Hierarchy does not get generated

my Date field named created_at is a Date/Time in Power Query when I load the data but not in the model (Data view). Why? How do I make the date hierarchy to get generated automatically?

 

 

  • Rupa01's avatar
    Rupa01
    1 month ago

    martinmark  You will have to first create the columns in the table which are required for creating the Date Hierarchy - possible in Direct Query Mode by using DAX. Then, you can use those columns to create a hierarchy as required.

    Note - Use MonthNum column to sort MonthName and if you want full Month name you can modify the DAX calculation as required.

     

    Create below DAX Calculated columns in the table in which you have created_at column - 

    Year = YEAR('Table'[created_at])
    
    Quarter = "Q" & QUARTER('Table'[created_at])
    
    MonthNum = MONTH('Table'[created_at])
    
    MonthName = 
    SWITCH(
        MONTH('Table'[created_at]),
        1, "Jan",
        2, "Feb",
        3, "Mar",
        4, "Apr",
        5, "May",
        6, "Jun",
        7, "Jul",
        8, "Aug",
        9, "Sep",
        10, "Oct",
        11, "Nov",
        12, "Dec"
    )

     

    πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing
    βœ… Solved your issue? Mark as Solution βœ”οΈ β€” help others find it faster

    Best regards,
    Rupasree Achari | BI & Fabric Analytics Engineer

11 Replies

  • Hello martinmark ,

     

    Sometimes you may see the difference ( when auto detect is off) , try below steps to force the model to recognize it as a Date/Time :

     

    1. In Power BI Desktop, go to the Data View 

    2. Click on your created_at column.

    3. Look at the top ribbon under column tools.

    4. Change Data Type to Date/Time (or Date if you don't need the timestamp).

    5. Change Format to your preferred date format

    I hope this helps,

     

    Did I answer your query ? Mark this as solution if this helps, Kudos are appreciated.

     

    Cheers,

     

  • Rupa01's avatar
    Rupa01
    Solution Sage

    Hi martinmark.,

     

    Date Hierarchy is automatically created in Power BI when Time Intelligence option is enabled in your current PBI Desktop File - File > Options & Settings > Options > Current File > Data Load > Time Intelligence (enable)

     

    Note that this will only work when the table storage mode is 'Import', column data type is Data or DateTime and the column is not in the many side of the relationship.

     

    Microsoft ReferenceAuto date/time in Power BI Desktop - Power BI | Microsoft Learn

     

     

    πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing
    βœ… Solved your issue? Mark as Solution βœ”οΈ β€” help others find it faster

    Best regards,
    Rupasree Achari | BI & Fabric Analytics Engineer 
  • Hi all, thanks for your answers!

    divyed , this is exactly my issue. Data Type is set automatically to Date/Time

    Rupa01, Time Intelligence option is enabled.

    The thing is I am actually using DirectQuery but the data size does not allow me to import. 

    • Rupa01's avatar
      Rupa01
      Solution Sage

      martinmark, Since the table is in Direct Query Mode, time intelligence option will not provide you automati Date Hierarchy creation - its a condition stated in the Microsoft Reference - Auto date/time in Power BI Desktop - Power BI | Microsoft Learn

      If you need Date hierarchy, you will have to manually create date hierarchy, Reference How to Create Date Hierarchy in Power BI? [With Examples]

       

       

      πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing
      βœ… Solved your issue? Mark as Solution βœ”οΈ β€” help others find it faster

      Best regards,
      Rupasree Achari | BI & Fabric Analytics Engineer
      • martinmark's avatar
        martinmark
        New Member

        Hi Rupa01 , thanks for your further answer!

        The problem is that none of the methods shown in the article apply to my case.

         

        • Power BI auto create date hierarchy: as we said, this does not work because it is a DirectQuery connection
        • Add date hierarchy Power BI: the "Select the Year column -> click..." method doesn't work because I do not have a Year column. My date column is a single column of timestamps as shown in the my question 
        • the SharePoint List method is basically the same as the first and Date Hierarchy does not get generated automatically in my case.
        • Power BI Add Week to Date Hierarchy: This does not work because I am in DirectQuery mode


        How come is this such of a challenge?

        Thanks

         

  • The reason your Date Hierarchy is not being generated automatically is usually because Power BI is no longer recognizing created_at as a true Date/Time column in the semantic model, even though it was a Date/Time type in Power Query.

    Power BI only creates the automatic hierarchy when:

    • The column data type in the Model view/Data view is Date or Date/Time.

    • The Auto date/time feature is enabled.

    • The column is not being treated as Text or another data type after loading.

    You can check the following:

    1. Verify the data type in the model

    Go to:

    Data view β†’ Select created_at column β†’ Column tools

    Check:

    • Data type = Date/Time

    • Format = your preferred date format

    If it shows Text, change it to Date/Time.


    2. Check Auto Date/Time setting

    Go to:

    File β†’ Options and settings β†’ Options β†’ Current File β†’ Data Load

    Enable:

    βœ… Auto date/time

    Then refresh the model.

    Note: This setting must be enabled before Power BI creates the hidden date tables.


    3. Check if you are using a DirectQuery or composite model

    Automatic date hierarchies are not always available depending on the storage mode and model design.

    For enterprise models, the recommended approach is usually not to rely on Auto Date/Time.


    4. Recommended approach: Create a Calendar table

    For production reports, create a proper Date table:

    Calendar =
    CALENDAR(
        MIN('Table'[created_at]),
        MAX('Table'[created_at])
    )

    Add columns:

    Year = YEAR('Calendar'[Date])
    
    Month = FORMAT('Calendar'[Date], "MMM")
    
    Month Number = MONTH('Calendar'[Date])
    
    Day = DAY('Calendar'[Date])

    Then:

    • Mark it as Date table

    • Create a relationship:

    Calendar[Date] β†’ Table[created_at]

    • Use the Calendar fields in visuals.

    This gives better control for:

    • Time intelligence

    • Fiscal calendars

    • Sorting months correctly

    • Year-over-year analysis

    So, if this is a small report, enabling Auto Date/Time may solve it. For a production Power BI model, a dedicated Calendar table is the recommended solution.

    For more information:

    πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing.

    βœ… Solved your issue? Mark this as the Accepted Solution βœ”οΈ

    Best regards, Prince Singh | Data Science & Microsoft Fabric Enthusiast

    • martinmark's avatar
      martinmark
      New Member

      hi ryan_mayu. unfortunately this does not work as the column used is not recognised as date in the first place