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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
caoellipsis
New Member

Shaping Month/Day/Year Problem

Hi there,

This is my first post.  I can't figure out how to get the date right.  

This is data for price per barrel of oil by month and year.  

 

 

I want the month and year data to be shaped into month/day/year, so april 1986 would read as 04/01/86 Formatted as a date.

 

I can't change the months columns format to date without causing errors, either now or after i unpivot.  Any ideas?  

 

 Capture.JPG

 

 

 

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

You first change the number format of the first column to Whole Number and then "Unpivot other columns".  Rename the attribute column as Months.  Click on Close and Load.  Then write this calculated column formula

 

=1*("1/"&[Month]&"/"&[Year])

 

Format this calculated column as Date.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
caoellipsis
New Member

Thanks guys!... both solutions worked.  

I was tinkering with the switch function, but ultimately the date = months expression was easier to implement. 

But both answers will help in my PowerBI quest.

Cheers,

Chris

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

 

You first change the number format of the first column to Whole Number and then "Unpivot other columns".  Rename the attribute column as Months.  Click on Close and Load.  Then write this calculated column formula

 

=1*("1/"&[Month]&"/"&[Year])

 

Format this calculated column as Date.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ChrisMendoza
Resident Rockstar
Resident Rockstar

@caoellipsis,

 

Is this what you're going for?:

 

1.PNG

 

Unpivot the columns [Jan], [Feb], [Mar], etc. I used the built-in UI for this.

 

2.PNG

 

Use the following article - https://www.powerquery.training/portfolio/replicate-power-pivots-switch-function/

I modified to the following:

 

(input) =>
let
values = {
    {"Jan", 1},
    {"Feb", 2},
    {"Mar", 3},
    {input, "Undefined"}

},
Result = List.First(List.Select(values, each _{0}=input)){1}
in
Result

After you have the custom function, you can use it as an Add Column:

 

fnSwitchMMM([Attribute])

Lastly, you can now use DateTime.From ( ) as an Add Column then change Data Type to Date:

DateTime.From(#date([Column1],[Custom],1))

*review the 3rd argument for #date 

 

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.