Conditional Column

Warpug

New Member
Joined
Apr 13, 2017
Messages
19
Office Version
  1. 365
Platform
  1. Windows
I have a column that is populated with dates from 2018-current date. For business reasons I would Luik to add a column that looks to the value in the cell with the date which is in this format mm/did/yyyy and do the following:
if year=2018 then “Made in 2018”
if year=2019 then “Made in 2019”
the rest I would like to have a value returned that provides me with the quarter and year based on the date field.
Q1 2020 or 2021 depending on the year
Q2 2020 or 2021 depending on the year
Q3 2020 or 2021 depending on the year
Q4 2020 or 2021 depending on the year
this is relatively simple in excel, but in Power query I’m having a hard time with it.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Book13
CD
1Column1Custom
26/2/2018Made in 2018
37/24/2019Made in 2019
411/6/2018Made in 2018
53/10/2018Made in 2018
66/18/2020Q2 2020
77/6/2021Q3 2021
84/10/2020Q2 2020
92/7/2018Made in 2018
102/2/2019Made in 2019
1112/5/2019Made in 2019
126/25/2020Q2 2020
1312/17/2018Made in 2018
143/27/2020Q1 2020
153/10/2020Q1 2020
165/12/2021Q2 2021
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type date}}),
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Column1]), Int64.Type),
    #"Inserted Quarter" = Table.AddColumn(#"Inserted Year", "Quarter", each Date.QuarterOfYear([Column1]), Int64.Type),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Quarter",{{"Quarter", type text}, {"Year", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if [Year]= "2018" then "Made in 2018" else if [Year]= "2019" then "Made in 2019" else "Q" & [Quarter] & " " & [Year]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Year", "Quarter"})
in
    #"Removed Columns"
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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