How to correctly format dates in Power BI - date

I am connecting to a stored procedure in SQLServer, from the data source the column AnioMes arrives as follows:
Once loaded in PowerBI it has the same format as follows:
I would like to give the correct format separating the year and the month in new columns, someone can give me an orientation on how to do it.

If this is an import model, just convert the number to a date in PowerQuery. For beginners in Power Query Add Column From Examples is your friend.
If it's DirectQuery or Import, you should have a calendar table (aka a Date Dimension) in SQL Server that you can join this column to, and bring that into your model.

Related

Date Format in Power BI Hierarchical Slicer

I have a Power BI file that connects to a data model via SSAS. The data model origin is a SQL Server view with some computed columns added in via SSAS.
One of the visualisations is a Hierarchical Slicer that shows dates. The field is not one of the computed SSAS columns. It displays in DD/MM/YYYY format but when I place the file on a Power BI Report Server the format is Americanised to MM/DD/YYYY. I want it to be DD/MM/YYYY.
The same field is used to populate a table visualisation but in there it remains DD/MM/YYYY. Just the slicer is affected.
This blog https://community.powerbi.com/t5/Desktop/date-format-in-slicer/td-p/215627 seemed to have the answer I needed but these settings were already applied and still the slicer shows MM/DD/YYYY.
Its not a problem when I open the pbix file locally; there, the slicer shows the dates as DD/MM/YYYY, its just when its on the server. The same problem persists in Test and Production and I have checked those settings and they are as the blog indicates. Other blogs identify this with the slicers but do not present a real solution as its not seen as a problem in those topics.
I've only spent a month working with Power BI so have no real experience to draw upon. I know that SQL Server defaults to American English when connecting to a database and I have changed that to British English but still the same problem. How do I get the slicer showing as DD/MM/YYYY as in my local copy?
Select the Date column and then go to the Modeling tab and change Format to whatever Date format you want.
OR
You can create a calculated column using the FORMAT method in DAX to convert date format as you want.
See reference here: https://msdn.microsoft.com/en-us/library/ee634398.aspx
Power BI is missing the formatting in their recent releases. However, the below solution works for me:
Create a Calculated Column ref. the original Date column and apply "Short Date" format for Date, example:
Transaction Date =
FORMAT(DATE(
YEAR([Transaction_Date]),
MONTH([Transaction_Date]),
DAY([Transaction_Date])
), "Short Date")

How to cast date column in SQL Server 2008 R2 to have drill down effect in the Excel format

I'm very new on this blog and probably I am not expressing my self correctly, but what I want is: I have a stored procedure where I am grabbing data and inside there I have a date column. I am using that stored procedure to create a report using SSRS and when I am exporting the report to Excel format and applying filter on date column I'd like to have a drill down effect on filter which shows first year and when I toggle down it should show me the month and then the days.
So how should I convert the date column that I can have a drill down effect?
CONVERT(VARCHAR(11), ORIGINAL_ORDER_DATE.THE_DATE, 103) AS ORIGINAL_ORDER_DATE
This is how i'm casting my date column inside the stored procedure.
This is how my date column look in Excel
This is how I'd like to have it

how to take off time in date time tabular model

I have a date dimension table and I have a Date column in that table it has datekey, fulldatekey, Date, DayofMonth, Dayofyear, month, ect. the Date column only has yyyy-mm-dd, but when I bring it into my tabular cube model it appends a 12:00:00 A.M time to the end of it. I was wanting to know how do I remove the time to only have the date. I am building a tabular cube in ssdt to bring into power bi
According to this Microsoft site,
In contrast to Microsoft Excel, which stores dates as a serial number,
PowerPivot date functions always return a datetime data type. However,
you can use formatting to display dates as serial numbers if you want.
From my "limited" experience, you can change the date formatting in one column, but when you reference it from another column, it will once again include the 12:00:00 AM time as part of the date when it displays in the new column. I assume this is because, as Microsoft says in that website,"PowerPivot date functions always return a datetime data type."
Edit Query -> Transform Tab -> Choose Data Type
That's my best guess.

Postgres timestamp to date

I am building a map in CartoDB which uses Postgres. I'm simply trying to display my dates as: 10-16-2014 but, haven't been able to because Postgres includes an unneeded timestamp in every date column.
Should I alter the column to remove the timestamp or, is it simply a matter of a (correct) SELECT query? I can SELECT records from a date range no problem with:
SELECT * FROM mytable
WHERE myTableDate >= '2014-01-01' AND myTableDate < '2014-12-31'
However, my dates appear in my CartoDB maps as: 2014-10-16T00:00:00Z and I'm just trying to get the popups on my maps to read: 10-16-2014.
Any help would be appreciated - Thank you!
You are confusing storage with display.
Store a timestamp or date, depending on whethether you need time or not.
If you want formatted output, ask the database for formatted output with to_char, e.g.
SELECT col1, col2, to_char(col3, 'DD-MM-YY'), ... FROM ...;
See the PostgreSQL manual.
There is no way to set a user-specified date output format. Dates are always output in ISO format. If PostgreSQL let you specify other formats without changing the SQL query text it'd really confuse client drivers and applications that expect the date format the protocol specifies and get something entirely different.
You have two basic options.
1 Change the column from a timestamp to a date column.
2 Cast to date in your SQL query (i.e. mytimestamp::date works).
In general if this is a presentation issue, I don't usually think that is a good reason to muck around with the database structure. That's better handled by client-side processing or casting in an SQL query. On the other hand if the issue is a semantic one, then you may want to revisit your database structure.

db2 getting business dates between given dates

I have a table called "Publicholidays" where in dates are stored as Varchar.
My query should fetch all values from say table xxxx between the user selected dates that exclude the weekends(sat,sun), public holidays. I am new to DB2 so can anyone suggest me ideas please
Note: in DB dates are stored as String.
Mistake #1 - Storing dates as strings. Let's hope you have at least stored them YYYY-MM-DD and not MM-DD-YYYY.
Mistake #2 - Instead of a "Publicholidays" table, you need a Calendar (aka Dates or date conversion) table. It should have a record for every day along with a few flag columns BUSINESS_DAY, WEEKEND, PUBLIC_HOLIDAY. Alternatively, you could have a single DAY_TYPE column with values for business day, weekend and holiday. You'll also want to have a STRING_DATE column to make conversion between your string date and a true date easier.
Google SQL Calender table and you'll find lots of examples and discussions.
Lastly, strongly consider fixing your DB to store dates in a date column.