Forum Discussion

cathoms's avatar
cathoms
Icon for Responsive Resident rankResponsive Resident
5 years ago
Solved

How do I create date column from quarter and year?

I am getting data from a folder. Each excel workbook in the folder has a column called Dataset that indicates the quarter and year the data are from in the format 1Q 2021, 2Q 2021, etc. I can easily ...
  • TomMartens's avatar
    5 years ago

    Hey cathoms ,

     

    in Power Query you can create a custom function and use the function. #date( year, month, day) to create a date. You have to be aware that all parameters have to be numeric, meaning you have to be wrap the Power Query function Number.FromText( ... ) around each non-numeric parameter https://docs.microsoft.com/en-us/powerquery-m/number-fromtext

    Use 1 as the day parameter.

    The numeric parameter for the month can be derived by the quarter number (the numeric part) and some math. The formula below

    = ( Quarternumber - 1 ) * 3  + 3

    returns the numeric value that represents the last month of a quarter

    1 --> 3

    2 --> 6

    Until now #date( ... ) will always be a date like 1st of September Year, if the quarternumber 3 is extracted from the column value quarter.

    Finally you can put #date(...) into the function Date.EndOfMonth( ... ) and you have a date like 31st of September.

     

    Hopefully, this will help to tackle your challenge. If not prepare a pbix file that contains sample data, upload the file to  to onedrive or dropbox and share the link. If you are using Excel to create the sample data, share the xlsx as well. As we are talking about using Power Query to create the date column it's necessary that we can access the source data as well. For this the xlsx or using the input method to enter sample data.

     

    Regards,

    Tom