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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pedroccamara
Helper II
Helper II

Date function

Hi guys

I'm trying to add a column with a date. I have two columns, two fields, year and month, both numeric values.

The idea is something like this... =DATE((YEAR)Anod, (Month)Mesd) and of course it's not working.

I have two questions:

1. How can i learn the formulas wich are available and how to aply them (youtube videos for example)

2. How do i make this function to work

Many thanks for your reply

Best regards

Pedro

2 ACCEPTED SOLUTIONS

@pedroccamara Are you attempting to do this in the query editor? If so, don't. The above solution is DAX, and you can implement by just right clicking on the table you want to apply the new column to and click on "New colomn" - this is where you would input the DAX syntax.

Using the query editor allows you to use "M" code to create columns etc. 2 different languages.


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

View solution in original post

v-haibl-msft
Employee
Employee

@pedroccamara

 

If you want to add the date column in Query Editor, you can add a custom column with following formula.

Number.ToText ( [Month] ) & "/" & "1" & "/" & Number.ToText ( [Year] )

Date function_1.jpg

 

Then change the type of this column to “Date”.

Date function_2.jpg

 

If you want to use DAX, please following the solution provided by Eno1978.

 

Best Regards,

Herbert

View solution in original post

5 REPLIES 5
v-haibl-msft
Employee
Employee

@pedroccamara

 

If you want to add the date column in Query Editor, you can add a custom column with following formula.

Number.ToText ( [Month] ) & "/" & "1" & "/" & Number.ToText ( [Year] )

Date function_1.jpg

 

Then change the type of this column to “Date”.

Date function_2.jpg

 

If you want to use DAX, please following the solution provided by Eno1978.

 

Best Regards,

Herbert

@pedroccamara Looks like something like this would work.

Date = FORMAT(([Month] & "/01/" & [Year]), "mm-dd'yyyy")

Then just change the Data Type to Date, and set to whatever format you want. My assumption is that since you don't have a "Day" that you would just default to the first day of the month.


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

Hello Eno

I've just change the field names like this ... FORMAT(([Mês] & "/01/" & [Ano]), "mm-dd'yyyy") and it gives me an expression error "The name FORMAT wasn't recognized"...

Any ideas?

@pedroccamara Are you attempting to do this in the query editor? If so, don't. The above solution is DAX, and you can implement by just right clicking on the table you want to apply the new column to and click on "New colomn" - this is where you would input the DAX syntax.

Using the query editor allows you to use "M" code to create columns etc. 2 different languages.


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

You're the MAN!!

Thank you very much

Best regards

Pedro

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.