Forum Discussion

EsterBR's avatar
EsterBR
Helper II
2 years ago
Solved

SWITCH - 2 conditions

Hi,

 

I have created the following formula with SWITCH:

 

Budget Q/Month =
SWITCH (
    SELECTEDVALUE ( 'Calendar'[Month Name] ),
    "August", [Budget MAX],
    "September", [Budget MAX],
    "October", [Budget MAX],
    "November", [Budget MAX],
    "December", [Budget MAX],
    [Budget SUM]
)
 
I would like to add another condition with and. For example if 'Calendar'[Month Name] = "August" AND "September" then  [Budget MAX]. How can I add that condition to that formula? Thanks!
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hii EsterBR ,

    You can use this measure

    Budget Q/Month =
    SWITCH (
        TRUE(),
        AND('Calendar'[Month Name]  = "August", 'Calendar'[Month Name]  = "September")  [Budget MAX],
        [Budget SUM]
    )
     
    Similarly you can add other conditions also.
    Thankyou.

5 Replies

  • TheoC's avatar
    TheoC
    Community Champion

    Hi EsterBR 

     

    You can modify it slightly by adding the SWITCH you have as a VAR, then adding another VAR for the special condition. For example:

    Budget Q/Month =


    VAR SelectedMonth = SELECTEDVALUE ( 'Calendar'[Month Name] )
    VAR _Condition = // Add the condition here

    RETURN

    IF (

         _Condition ,
              // Calculation if _Condition is TRUE ,
             SWITCH (
                      SelectedMonth ,
                               "August", [Budget MAX] ,
                               "September", [Budget MAX] , 
                               "October", [Budget MAX] ,
                               "November", [Budget MAX] ,
                               "December", [Budget MAX] ,
                               [Budget SUM]
                      )
       )

    I hope this makes sense / helps.

     

    Theo 🙂

     

    • EsterBR's avatar
      EsterBR
      Helper II

      Thanks TheoC , Where do I add the AND? I need the Month Name to be "August" AND "September"

      • TheoC's avatar
        TheoC
        Community Champion

        Hi EsterBR 

         

        You can add the AND condition as the VAR _Condition

         

        Let me know if you want me to add this for you.

         

        Theo

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hii EsterBR ,

    You can use this measure

    Budget Q/Month =
    SWITCH (
        TRUE(),
        AND('Calendar'[Month Name]  = "August", 'Calendar'[Month Name]  = "September")  [Budget MAX],
        [Budget SUM]
    )
     
    Similarly you can add other conditions also.
    Thankyou.
  • Hi TheoC , Can you add it for me? I do not have a lot of experience with DAX and I would like to know where to place it.