Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract Month and Year from column in PowerBI powerquery

I have a column (monthyear) in the image below. I want to extract the Month and year from the column to put it in the new column. Note: In my dataset this information goes for every day of the year

So the new column would look like: 01/2020 01/2020 01/2020 etc.

enter image description here

like image 998
lydol Avatar asked Oct 22 '25 23:10

lydol


1 Answers

In Power Query, use some of the date functions.

To get the year it will be

Date.Year([monthyear])

For the month, it will depend on how you want to format it. Using the month of June as an example:

To get 'Jun'

Date.ToText([monthyear],"MMM")

To get the month number in the format 06

Number.ToText(Date.Month([monthyear]), "00")

Just to get the number 6 it will be:

Date.Month([monthyear])

In DAX use the date functions

For year the calculated column will be:

YEAR([monthyear])

For the month:

MONTH([monthyear])

I would always do a much data transformation in Power Query when you can before it gets to the data model.

like image 113
Jon Avatar answered Oct 25 '25 08:10

Jon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!