Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
eliassal
Helper II
Helper II

Date/Time Issue between SQL and Power BI Desktop

Hi, I have a select statement that runs fine in SSMS it returns 1st column as date as follows

 

SELECT
CAST(timestamp AS DATE) AS daily,
Datepart(Year, Timestamp) as Year,
Datepart(Month, Timestamp)-1 as Month,
Datepart(Day, Timestamp) as Day,
COUNT(ipaddress) AS ipperday............

.........

 

The outcome is

2020-02-17 2020 1 17 506
2020-02-18 2020 1 18 2
2020-02-19 2020 1 19 539

 

Whereas when, in transformation in PowerBI desktop, New query, I execute the same exact query, 1st colmn comes back with Date and time as follows

3/28/2020 12:00:00 AM 2020 3 28 1
8/3/2020 12:00:00 AM 2020 8 3 631
5/15/2020 12:00:00 AM 2020 5 15 363
2/23/2020 12:00:00 AM 2020 2 23 1128

 

I use the Horizantal Bar chart from MS and it duispalys an ugly text on the bars a follows

eliassal_1-1596469303295.png

 

 

When I change the type in Power BI to date, my report does not get execy=uted because it is a direct query 

eliassal_2-1596469370075.png

So how can I overcome this and have the exact same result in Power BI without time? Thanks

1 ACCEPTED SOLUTION

Hi @eliassal ,

Becasue date type in sql server is corresponded with date/time type in power bi desktop.

If you want to use horizontal bar chart to show the date without time, I think you should contact the owner of this custom visual because this custom visual shows time automatically and we could not change it settings.

One temporary way to use this visual to show date without time is to change the data type in cast() function from date to varchar:

date type.pngchart.png

 

Or you can use default bar charts in power bi such as Stacked bar chart, change the format of daily field and change the type of Y-axis as Categorical:

format.pngY- axis.png

 

Best Regards,
Yingjie 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

11 REPLIES 11
simrantuli
Continued Contributor
Continued Contributor

Hi @eliassal ,

 

How are you doing this transformation?

I recreated your scenario and changed the timestamp to Date in Power query and it worked fine for me. Didn't give me any errors.

 

simrantuli_0-1596479461726.png

 

simrantuli_1-1596479484988.png

 

However, if it still doesn't work for you, you could change the format of this column in 'Model' view. Please find below the screenshot.

simrantuli_0-1596479751930.png

Regards

Simran Tuli

Power query, where in Power BI? I am confused, I thought that Power query is used in excel !!!

Hi @eliassal ,

Based on my test, I can get the same result using the sql statement in power bi and need not change the data type of daily column as date type.

You can open power query editors by choosing transforming data.

sql server.pngpower query.png

You can try to paste your sql statement in the advanced options when connecting to sql server to check. Please note that ORDERBY cannot be quoted under direcr query mode.

desktop.png

 

Best Regards,
Yingjie Li

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

 

 

Li, you are showing exactly the same thing, your text in the horizantal bar is showing date and time on each bar as mine which is my problem. This is exactly what I do, in the preview in powerbi it always shows date time I am not sure you have rad my initial post. I want to get rid of the zone time phrase, just want to see the date on the bar

So I need iot to be

eliassal_0-1596525260099.png

 

instead of

 

eliassal_1-1596525274481.png

 

 

Li, you are showing the same thing which I want to get rid of the time in the 1st column

eliassal_0-1596525654091.png

The initial question, why Power BI adding time by iteself?

Hi @eliassal ,

Becasue date type in sql server is corresponded with date/time type in power bi desktop.

If you want to use horizontal bar chart to show the date without time, I think you should contact the owner of this custom visual because this custom visual shows time automatically and we could not change it settings.

One temporary way to use this visual to show date without time is to change the data type in cast() function from date to varchar:

date type.pngchart.png

 

Or you can use default bar charts in power bi such as Stacked bar chart, change the format of daily field and change the type of Y-axis as Categorical:

format.pngY- axis.png

 

Best Regards,
Yingjie Li

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

The owner is MDS corporation 😂 thanks for the tips, I have already started to use the stacked bar chart but the other visual is much nicer for visualization

Hi @eliassal ,

If the above posts help, please kindly mark it as a solution to help others find it more quickly. Thanks!


Best Regards,
Yingjie Li

BA_Pete
Super User
Super User

Hi @eliassal ,

 

You could try a different method of truncating your datetime to date via the SQL query.

 

Check out this thread for some good suggestions:

https://stackoverflow.com/questions/923295/how-can-i-truncate-a-datetime-in-sql-server/923322

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




amitchandak
Super User
Super User

@eliassal , how you have done these transformations.

There are quite a few stuff is not supported as a custom column in Direct query

 

Check-in dax as a calculated column.

 

Format example you can take from

https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calend...

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

It is a straight forward simple select

 

SELECT
CAST(timestamp AS DATE) AS daily,
Datepart(Year, Timestamp) as Year,
Datepart(Month, Timestamp)-1 as Month,
Datepart(Day, Timestamp) as Day,
COUNT(ipaddress) AS ipperday
FROM mytable
WHERE timestamp< GETDATE()
GROUP BY
CAST(timestamp AS DATE),
Datepart(Year, Timestamp),
Datepart(Month, Timestamp)-1,
Datepart(Day, Timestamp)
ORDER BY daily ASC

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.