Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Creating a column converting months to seasons

Hi there.

 

I have a table "Dates" that looks like below.

 

I would like to create a seasons column (in red) but unsure of the dax.

 

Nov, Dec, Jan = Winter

Feb, March, April = Spring

May, June, July = Summer

Aug, Sept, Oct - Autumn

 

StartMonth

Season
JanuaryWinter
JanuaryWinter
FebruarySpring
MarchSpring
AprilSpring
May Summer

 

Would really appreciate some help with this.

  • Anonymous Well, you could always do a SWITCH statement:

    Season Column = 
      SWITCH([StartMonth],
        "November","Winter",
        "December","Winter",
        "January","Winter",
        "February","Spring",
        "March","Spring",
        "April","Spring",
        "May","Summer",
        "June","Summer",
        "July","Summer",
        "Autumn"
      )
  • Anonymous 

     

    Another version of Switch can be this one:

    New Column = SWITCH(
    TRUE(),
    'Table'StartMonth = "December" || 'Table'StartMonth = "January" || 'Table'StartMonth = "February", "Winter",
    'Table'StartMonth = "March" || 'Table'StartMonth = "April" || 'Table'StartMonth = "May", "Spring",
    'Table'StartMonth = "June" || 'Table'StartMonth = "JUly" || 'Table'StartMonth = "August", "Summer",
    'Table'StartMonth = "September" || 'Table'StartMonth = "October" || 'Table'StartMonth = "November", "Autumn",
    BLANK()
    )

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you both Greg_Deckler and themistoklis - both worked and I've learned something new!! Only new to powerbi so just learning as I go. 

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Anonymous Well, you could always do a SWITCH statement:

    Season Column = 
      SWITCH([StartMonth],
        "November","Winter",
        "December","Winter",
        "January","Winter",
        "February","Spring",
        "March","Spring",
        "April","Spring",
        "May","Summer",
        "June","Summer",
        "July","Summer",
        "Autumn"
      )
  • themistoklis's avatar
    themistoklis
    Icon for Community Champion rankCommunity Champion

    Anonymous 

     

    Another version of Switch can be this one:

    New Column = SWITCH(
    TRUE(),
    'Table'StartMonth = "December" || 'Table'StartMonth = "January" || 'Table'StartMonth = "February", "Winter",
    'Table'StartMonth = "March" || 'Table'StartMonth = "April" || 'Table'StartMonth = "May", "Spring",
    'Table'StartMonth = "June" || 'Table'StartMonth = "JUly" || 'Table'StartMonth = "August", "Summer",
    'Table'StartMonth = "September" || 'Table'StartMonth = "October" || 'Table'StartMonth = "November", "Autumn",
    BLANK()
    )