cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
javirmerino Helper III
Helper III

Combining calculated Date & Time Fields

Hi guys, i'm trying to use the below query to determine a value based on a number of fields;

if  Value.Compare([ReceivedTime], #time(17,0,0)) = 1
 then [NextWorkingDay]  +  [StartTime] 
else [ReceivedDate]  + [StartTime]

The syntax seems to be ok but i'm getting an expression.error as i'm unable to use the "+" operator to combine the date and time as i usually would in excel.

Whats the correct method of working to get around this? I tried using SELECTEDVALUE on each time and date element but this was causing further issues that i couldnt understand.

 

Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Combining calculated Date & Time Fields

Hi @javirmerino ,

 

We can create a custom column using following query to meet your reqirement:

 

if  Value.Compare([ReceivedTime], #time(17,0,0)) = 1
 then DateTime.From([NextWorkingDay])+Duration.FromText(Time.ToText([StartTime],"hh:mm:ss"))
else DateTime.From([ReceivedDate] )+Duration.FromText(Time.ToText(Text.From([StartTime],"hh:mm:ss"))

 

Or 

 

if  Value.Compare([ReceivedTime], #time(17,0,0)) = 1
 then DateTime.From(Date.ToText([NextWorkingDay]) & Time.ToText([StartTime]," hh:mm:ss"))
else DateTime.From(Date.ToText([ReceivedDate]) & Time.ToText([StartTime]," hh:mm:ss"))

 


Best regards,

 

Community Support Team _ Dong Li
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

6 REPLIES 6
javirmerino Helper III
Helper III

Re: Combining calculated Date & Time Fields

i've resolved one issue by changing the +'s to &'s (which worked lovely!) but now its caused a secondary issue which i believe is something to do with my Next Working Day measure, as any values using this are returning an error;

Expression.Error: We cannot apply field access to the type Text.
Details:
    Value=Σ Measures
    Key=NextWorkingDay

 

Would this be anything to do with one being a measure written in DAX and one being a query written in #M? If so, do i just need to rewrite my [NextWorkingDay] measure in PowerQuery?

Microsoft artemus
Microsoft

Re: Combining calculated Date & Time Fields

Change the column type to DateTime to fix this.

javirmerino Helper III
Helper III

Re: Combining calculated Date & Time Fields

Hi @artemus, thanks for your response. I cringed when i saw it as i thought "it cant be that simple, surely?!" - and fortunately for me, it wasn't! 

 

I'm unable to view or format the [NextWorkingDay] column in QueryEditor as its a DAX measure so i'm assuming the only way to amend the formatting of the output is via the query itself?

 

Or could the query be converted into M so its added as a calculated column instead?

NextWorkingDay = 
minx( 
    FILTER(
        ALL(Dim_Date), Dim_Date[IsWeekday] = TRUE  && 
        Dim_Date[IsHolidayUK] = FALSE && 
        Dim_Date[Date] > SELECTEDVALUE('SysAid Extract'[ReceivedDate]) 
    ),Dim_Date[Date])

 

Super User I
Super User I

Re: Combining calculated Date & Time Fields

hello @javirmerino 

 

I'm a little confused where exactly you want to have the solution. If you are still going for the Power Query option try to change your code as follows:

if  Value.Compare([ReceivedTime], #time(17,0,0)) = 1
 then DateTime.From([NextWorkingDay])+Duration.FromText(Text.From([StartTime] )) 
else DateTime.From([ReceivedDate] )+Duration.FromText(Text.From([StartTime] ))


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

javirmerino Helper III
Helper III

Re: Combining calculated Date & Time Fields

Thanks @Jimmy801. Please excuse me if i confuse you at all - i've only been using PowerBI for around a month (Tableau convert, here) so i'm unsure of the best practices and when to use M or DAX. Any guidelines or rules of thumb would be appreciated here.

 

I will give the code a go shortly and will mark as the answer if this works out.

 

Thanks again!

Community Support
Community Support

Re: Combining calculated Date & Time Fields

Hi @javirmerino ,

 

We can create a custom column using following query to meet your reqirement:

 

if  Value.Compare([ReceivedTime], #time(17,0,0)) = 1
 then DateTime.From([NextWorkingDay])+Duration.FromText(Time.ToText([StartTime],"hh:mm:ss"))
else DateTime.From([ReceivedDate] )+Duration.FromText(Time.ToText(Text.From([StartTime],"hh:mm:ss"))

 

Or 

 

if  Value.Compare([ReceivedTime], #time(17,0,0)) = 1
 then DateTime.From(Date.ToText([NextWorkingDay]) & Time.ToText([StartTime]," hh:mm:ss"))
else DateTime.From(Date.ToText([ReceivedDate]) & Time.ToText([StartTime]," hh:mm:ss"))

 


Best regards,

 

Community Support Team _ Dong Li
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

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors