Power Query to Get Fiscal Quarter Based on Month Name

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,214
Office Version
  1. 365
Platform
  1. Windows
I want to create a custom column in Power Query that would have a formula to get the fiscal quarter based on the month column name in my data set.

Oct, Nov, Dec = Q1
Jan, Feb, Mar = Q2
Apr, May, Jun = Q3
Jul, Aug, Sep = Q4

As noted above, the month column in my data set only use the first three character for any given month. Can someone help me on what Power Query function I would need to use to get the Fiscal Quarter based on the three character month name?
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Assuming the column to check is called [Month] , then Add column...Custom column... and use this code


Code:
if [Month]="Jan" or [Month]="Feb" or [Month]="Mar" then "Q1" else if [Month]="Apr" or [Month]="May" or [Month]="Jun" then "Q2" else if [Month]="Jul" or [Month]="Aug" or [Month]="Sep" then "Q3" else "Q4"

that would produce something like this:

Code:
    #"Added Custom" = Table.AddColumn(#"PreviousStep", "CustomQuarter", each if [Month]="Jan" or [Month]="Feb" or [Month]="Mar" then "Q1" else if [Month]="Apr" or [Month]="May" or [Month]="Jun" then "Q2" else if [Month]="Jul" or [Month]="Aug" or [Month]="Sep" then "Q3" else "Q4")
 
Upvote 0
Using a list of Month names:
Code:
MthName
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec



I used this M-Code to calculate quarters:
Code:
let
    Source              = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    DuplicateMthNameCol = Table.DuplicateColumn(Source, "MthName", "Qtr"),
    ConvertToDateText   = Table.TransformColumns(DuplicateMthNameCol, {{"Qtr", each "1-" & _ , type text}}),
    ConvertToDate       = Table.TransformColumnTypes(ConvertToDateText,{{"Qtr", type date}}),
    ConvertToQtr        = Table.TransformColumns(ConvertToDate,{{"Qtr", Date.QuarterOfYear}})
in
    ConvertToQtr

Is that something you can work with?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top