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
dannytan1112
Helper I
Helper I

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

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

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:

vyueyunzhmsft_0-1672020390501.png

(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 :

vyueyunzhmsft_1-1672020422963.png

 

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

 

View solution in original post

5 REPLIES 5
v-yueyunzh-msft
Community Support
Community Support

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:

vyueyunzhmsft_0-1672020390501.png

(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 :

vyueyunzhmsft_1-1672020422963.png

 

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

 

Hi,

 

It works for me now. Really thanks

Mahesh0016
Super User
Super User

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.

Hi Mahesh,

 

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

This is the table I received

dannytan1112_0-1672019680904.png

 

And this is it while I put it on the table

dannytan1112_1-1672019708958.png

 

 

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

 

dannytan1112
Helper I
Helper I

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

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.