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
WJ876400
Helper IV
Helper IV

IF statement

Hi

 

I have a table with each month of the year and I want to split them up so they are in Periods. What is the best way to do this in the query editor? thanks in advance

 

Period 1Period 2Period 3Period 4Period 1
Jan-19Feb-19Mar-19Apr-19May-19Jun-19Jul-19Aug-19Sep-19Oct-19Nov-19Dec-19Jan-20Feb-20
1 ACCEPTED SOLUTION

Perhaps try:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMU4rViVZyS00C076JRWDasaAIyq8E016leVA6ByJfmg6mg1MLwLR/cgmY9ssvA9MuqckQ9cSYHwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Date] = "Jan" or [Date]="Feb" or [Date]="Mar" then "Period 1" else if [Date]="Apr" or [Date]="May" or [Date]="Jun" then "Period 2" else if [Date]="Jul" or [Date]="Aug" then "Period 3" else "Period 4")
in
    #"Added Custom"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

Are those months and years text or do you convert them to dates? And you want this in the query editor, not DAX, correct?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

They come from the source as dates, in the query editor or as DAX which ever is easiest to do.

 

thanks for your help

WJ876400
Helper IV
Helper IV

Sorry the data has not displayed properly it should be 

 

Period 1Period 1Period 1Period 2Period 2Period 2Period 3Period 3Period 4Period 4
JanFebMarchAprilMayJuneJulyAugustSeptemberOctober

 

The month is coming from a date field

 

thanks

Perhaps try:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMU4rViVZyS00C076JRWDasaAIyq8E016leVA6ByJfmg6mg1MLwLR/cgmY9ssvA9MuqckQ9cSYHwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Date] = "Jan" or [Date]="Feb" or [Date]="Mar" then "Period 1" else if [Date]="Apr" or [Date]="May" or [Date]="Jun" then "Period 2" else if [Date]="Jul" or [Date]="Aug" then "Period 3" else "Period 4")
in
    #"Added Custom"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.