The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi,
I am trying to create a data series with every round hour between two dates. I came up with the below DAX code, but after a certain date it starts returning ..... ..:59:59 instead of ..... ..:00:00 .
Can somebody advise what is causing it and how to resolve it?
Thanks
Solved! Go to Solution.
Hi, @BLB
According to your description, you wabt to create a data series with every round hour between two dates.Right?
Here are the steps you can follow:
(1)This is my test data to situmulate your fact table:
(2)We can click "New table" and enter this dax:
DateHour Master =
VAR __YearMinusOne = YEAR(TODAY()) - 1
VAR __YearPlusOne = YEAR(TODAY())+1
VAR __Table =
CALENDAR(DATE(__YearMinusOne,1,1),DATE(__YearPlusOne,12,31))
var _time= SELECTCOLUMNS( GENERATESERIES(
Time(0,0,0),
TIME(23,0,0),
1/24) , "time", [Value] )
var _t = CROSSJOIN(__Table,_time)
RETURN
SELECTCOLUMNS( ADDCOLUMNS(_t,"tt",[Date]+[time]) ,"DateTime" , [tt])
(3)Then we can get the table and create relationship between two tables, the result is as follows:
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, @BLB
According to your description, you wabt to create a data series with every round hour between two dates.Right?
Here are the steps you can follow:
(1)This is my test data to situmulate your fact table:
(2)We can click "New table" and enter this dax:
DateHour Master =
VAR __YearMinusOne = YEAR(TODAY()) - 1
VAR __YearPlusOne = YEAR(TODAY())+1
VAR __Table =
CALENDAR(DATE(__YearMinusOne,1,1),DATE(__YearPlusOne,12,31))
var _time= SELECTCOLUMNS( GENERATESERIES(
Time(0,0,0),
TIME(23,0,0),
1/24) , "time", [Value] )
var _t = CROSSJOIN(__Table,_time)
RETURN
SELECTCOLUMNS( ADDCOLUMNS(_t,"tt",[Date]+[time]) ,"DateTime" , [tt])
(3)Then we can get the table and create relationship between two tables, the result is as follows:
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 Aniya,
Thank you it does work!
In the meantime I came across this article with a similar solution, but I find yours more elegant 🙂
Hi,
you can also add a column
If this post is useful to help you to solve your issue consider giving the post a thumbs up
and accepting it as a solution !
Hi @serpiva64 it does work, thank you!
But I don't really understand how the formatting will result in rounding - can you please explain, e.g. why will 11:59:59 turn into 12:00:00?
Thanks
@BLB Try this and then set your Value column to type Date/time.
DateHour Master =
VAR __YearMinusOne = YEAR(NOW()) - 1
VAR __YearPlusOne = YEAR(NOW()) + 1
VAR __Table =
ADDCOLUMNS(
GENERATESERIES(
DATE(__YearMinusOne,1,1),
DATE(__YearPlusOne, 12, 31),
1/24
),
"Date Time",ROUNDUP([Value],5)
)
RETURN
SELECTCOLUMNS(__Table,"Value",[Date Time])
Hi @Greg_Deckler , thank you for your prompt reply.
I tested it and it still behaves funny. In the generated table I can now see all the rounded dates&hours indeed. However, when I connect it with my fact table, it will not recognise some of the generated values, like the ones highlighted below: left column is from the fact table, right is from the generated table.
Do you have any suggestion why?
Thanks.
@BLB How about this?
DateHour Master =
VAR __YearMinusOne = YEAR(NOW()) - 1
VAR __YearPlusOne = YEAR(NOW()) + 1
VAR __Table =
ADDCOLUMNS(
GENERATESERIES(
DATE(__YearMinusOne,1,1),
DATE(__YearPlusOne, 12, 31),
1/24
),
"Date Time",DATE(YEAR([Value]),MONTH([Value]),DAY([Value])) + TIME(HOUR([Value]),0,0)
)
RETURN
SELECTCOLUMNS(__Table,"Value",[Date Time])
Thanks but still something weird keeps happinging with this. Somehow it generates the value 20/01/2021 21:00:00 twice!
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
21 | |
19 | |
18 | |
18 | |
14 |
User | Count |
---|---|
38 | |
35 | |
22 | |
20 | |
17 |