Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Recreating Case Statement in Dax

Hi,

 

I'm trying to recreate the following case statement in dax

 

'FY ' + cast(CASE  WHEN MONTH(jb.date_comp) > 3 THEN YEAR(jb.date_comp) + 1 ELSE YEAR(jb.date_comp)  END as varchar) AS COMP_FISCAL_YEAR_TEXT
,  CASE MONTH(jb.date_comp)  
    when 1 then 'P10 Jan'
    when 2 then 'P11 Feb'
    when 3 then 'P12 Mar'
    when 4 then 'P01 Apr'
    when 5 then 'P02 May'
    when 6 then 'P03 Jun'
    when 7 then 'P04 Jul'
    when 8 then 'P05 Aug'
    when 9 then 'P06 Sep'
    when 10 then 'P07 Oct'
    when 11 then 'P08 Nov'
    when 12 then 'P09 Dec'
    ELSE '0'END AS COMP_FISCAL_PERIOD

 

This produces two additional colunms

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous add new column with following expresssion

 

Would appreciate Kudos 🙂 if my solution helped.

COMP_FISCAL_YEAR_TEXT = 
VAR __month = MONTH(jb[date_comp])
VAR __year = YEAR(jb[date_comp]) 
RETURN
'FY ' & IF ( __month > 3, __year + 1, __year )

COMP_FISCAL_PERIOD =  
SWITCH (  MONTH(jb[date_comp])  ,
    1 , 'P10 Jan'
    2 , 'P11 Feb'
    3 , 'P12 Mar'
    4 , 'P01 Apr'
    5 , 'P02 May'
    6 , 'P03 Jun'
    7 , 'P04 Jul'
    8 , 'P05 Aug'
    9 , 'P06 Sep'
    10 , 'P07 Oct'
    11 , 'P08 Nov'
    12 , 'P09 Dec',
    '0'
)

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

parry2k's formula seems well. If you do not want to hardcode result with 'switch' function, you can try to use the following calculate column formula to dynamically generate tag based on conditions:

 

COMP_FISCAL_PERIOD =
VAR monthnum =
    MONTH ( [date_comp] )
VAR fm =
    IF ( monthnum <= 12, IF ( monthnum - 3 <= 0, monthnum - 3 + 12, monthnum - 3 ) )
RETURN
    IF (
        fm <> BLANK (),
        IF ( LEN ( fm ) < 2, "P0", "P" ) & fm
            & FORMAT ( [date_comp], " MMM" ),
        "0"
    )

 

1.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
parry2k
Super User
Super User

@Anonymous add new column with following expresssion

 

Would appreciate Kudos 🙂 if my solution helped.

COMP_FISCAL_YEAR_TEXT = 
VAR __month = MONTH(jb[date_comp])
VAR __year = YEAR(jb[date_comp]) 
RETURN
'FY ' & IF ( __month > 3, __year + 1, __year )

COMP_FISCAL_PERIOD =  
SWITCH (  MONTH(jb[date_comp])  ,
    1 , 'P10 Jan'
    2 , 'P11 Feb'
    3 , 'P12 Mar'
    4 , 'P01 Apr'
    5 , 'P02 May'
    6 , 'P03 Jun'
    7 , 'P04 Jul'
    8 , 'P05 Aug'
    9 , 'P06 Sep'
    10 , 'P07 Oct'
    11 , 'P08 Nov'
    12 , 'P09 Dec',
    '0'
)

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.