Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi.
When we extract a year,month or a quarter from a date column to create a new column, its data type is stored as either "Whole Number" or "text".
If we use Year=YEAR(datecolumn), it is stored as Whole Number and
if we use Year=FORMAT(datecolumn,"yyyy"), then it is stored as text.
And if we convert it to 'date' format, then the whole column value changes.
But it is common sense that the extracted column should be in date format only.
Does anyone know a way to achieve it?
Regards,
Sanket Bhhagwat
Solved! Go to Solution.
@SanketBhagwat wrote:
Suppose if I am using SAMEPERIODLASTYEAR function and if i extract date using ;
Year=FORMAT(Datecolumn,"yyyy")LastYear=CALCULATE(SUM(Sales),SAMEPERIODLASTYEAR(Year)),
then I will get an error as 'the column referenced to SAMEPERIODLASTYEAR is not a date column'.
Then you would use the original dateColumn that you reference in the expression for your year column. You only need one datetime column in your date table. All the other columns can be strings and numbers.
And if you are using any of the time intelligence functions like SAMEPERIODSLASTYEAR you really need to be using a dedicated date table. You should not be using a datetime column from a fact table or you risk getting incorrect results.
@SanketBhagwat wrote:
But it is common sense that the extracted column should be in date format only.
I disagree. If we take your example and we extract the year from todays date it make much more sense to store this at the number 2021 and then change the summarization option to "Don't Summarize".
You cannot store just a year in a datetime column you have to include some value for the month and day and then you are wasting storeage on values you do not need.
Agreed @d_gosbell .
But suppose if we want to use that column in a function which specifically requires a date column.
What to do then?
I posted this blog so as to make sure whether there is a way or not.
Even if there is no way, I can still implement my DAX.
Suppose if I want LastYearSum, then instead of SAMEPERIODLASTYEAR, I can use DATESINPERIOD and for that I would not need a separate YEAR column.
Anyways, thanks for your reply.
Appreciate your response.
Regards,
Sanket Bhagwat
@SanketBhagwat , how does year as date helps?
We can use year start or the year or end date if we need
like startofyear([Date])
or date(Year([Date],1,1)
Start of month = eomonth([Date],-1) +1
you have startofmonth,startofquarter also.
See if these can help to achieve what you want.
Suppose if I am using SAMEPERIODLASTYEAR function and if i extract date using ;
Year=FORMAT(Datecolumn,"yyyy")
LastYear=CALCULATE(SUM(Sales),SAMEPERIODLASTYEAR(Year)),
then I will get an error as 'the column referenced to SAMEPERIODLASTYEAR is not a date column'.
@SanketBhagwat wrote:
Suppose if I am using SAMEPERIODLASTYEAR function and if i extract date using ;
Year=FORMAT(Datecolumn,"yyyy")LastYear=CALCULATE(SUM(Sales),SAMEPERIODLASTYEAR(Year)),
then I will get an error as 'the column referenced to SAMEPERIODLASTYEAR is not a date column'.
Then you would use the original dateColumn that you reference in the expression for your year column. You only need one datetime column in your date table. All the other columns can be strings and numbers.
And if you are using any of the time intelligence functions like SAMEPERIODSLASTYEAR you really need to be using a dedicated date table. You should not be using a datetime column from a fact table or you risk getting incorrect results.
User | Count |
---|---|
76 | |
75 | |
46 | |
31 | |
27 |
User | Count |
---|---|
99 | |
91 | |
51 | |
49 | |
45 |