Forum Discussion

dannytan1112's avatar
dannytan1112
Icon for Helper I rankHelper I
3 years ago
Solved

24 hours datettime

Hi, 

 

I have a question since i found no answer to it. I have tried generate , dateadd but still can't find the answer.

I would like to make a measure for every hour range from min datetime and max datetime from a column in a MyTable.[Date]

How can i write this code?

 

Thanks a lot

  • Hi , dannytan1112 

    According to your description, you want to "every hour range from min datetime and max datetime".And bu another, if you create a measure , it can not return a list , measure in Power Bi can only return a value.

    Here are the steps you can refer to :
    (1)This is my test data:

    (2)We can click "New Table" and enter:

    Table 2 = GENERATESERIES(
    MIN('My Table'[Column1]),
    MAX('My Table'[Column1]),
    1/24)

    Then we can get this table you want to :

     

    For more information, you can refer to :
    Creating a List of Numbers or Dates in Power BI using GenerateSeries Function in DAX - RADACAD

    CALENDAR function (DAX) - DAX | Microsoft Learn

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

     

5 Replies

  • Here is my code

    Measure = 

    Var MaxDateTime = Max('MyTable'[DateTime])

    Var MinDateTime = Min('MyTable'[DateTime])

    RETURN

         SELECTCOLUMNS(                                    //I did try with addcolumn as well, dont work

             CALENDAR(MinDateTime,MaxDateTime),

             "Hourly Interval", [Date] + TIME(1,0,0)

             )

     

    Thanks

  • Clock Hour&Minutes =
    VAR MaxDate = MAX('Table'[ScannedDate])
    VAR MaxHours = HOUR(MaxDate)
    VAR MaxMinutes = MINUTE(MaxDate)
    VAR MaxinHours = (MaxHours*60)+MaxMinutes
    //
    VAR MinDate = MIN('Table'[ScannedDate])
    VAR MinHours = HOUR(MinDate)
    VAR MinMinutes = MINUTE(MinDate)
    VAR MininHours = (MinHours*60)+MinMinutes
     
    RETURN
    MaxinHours-MininHours
     
     
    **If this post helps, please consider accept as solution to help other members find it more quickly.
    • dannytan1112's avatar
      dannytan1112
      Icon for Helper I rankHelper I

      Hi Mahesh,

       

      Thanks for the reply. But it seems like it doesn't work for me. 

      This is the table I received

       

      And this is it while I put it on the table

       

       

      So the idea is that I have a column let say it starts with 21st dec 2022 and my last data is 28th dec 2022, in some of my data, let say 24th dec from 1 pm to 4 pm has no data (therefore no row of datetime in that column. But i would like to show it in my graphic as no data. Therefore i need to have a measure that will generate

       

      21/12/2022 12:00:00 AM //My first datetime in my dataset

      21/12/2022 01:00:00 AM

      21/12/2022 02:00:00 AM

      :

      :

      :

      24/12/2022 12:00:00 PM

      24/12/2022 01:00:00 PM

      :

      :

      Until Max Date (Last hour in my dataset)

      24/12/2022 02:00:00 PM

       

       

      Really thanks for your help sir

       

  • Hi , dannytan1112 

    According to your description, you want to "every hour range from min datetime and max datetime".And bu another, if you create a measure , it can not return a list , measure in Power Bi can only return a value.

    Here are the steps you can refer to :
    (1)This is my test data:

    (2)We can click "New Table" and enter:

    Table 2 = GENERATESERIES(
    MIN('My Table'[Column1]),
    MAX('My Table'[Column1]),
    1/24)

    Then we can get this table you want to :

     

    For more information, you can refer to :
    Creating a List of Numbers or Dates in Power BI using GenerateSeries Function in DAX - RADACAD

    CALENDAR function (DAX) - DAX | Microsoft Learn

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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