Forum Discussion

apmulhearn's avatar
apmulhearn
Helper III
3 years ago
Solved

Help with Date/Time + Text Concatenate Sort in Chart Visualization - out of order due to 1 in month

Hi,   Below is a chart visualization and the issue I'm trying to fix. "New Subject" is a combination of Year/Month and a subject line. I want the ones highlighted in yellow to be at the top whe...
  • rsbin's avatar
    rsbin
    3 years ago

    apmulhearn ,

    The SWITCH function is structured like this:

    SWITCH(
             TRUE(),
              Condition1, Result1,

              Condition2, Result2,

              Else all other conditions.

    https://learn.microsoft.com/en-us/dax/switch-function-dax

    SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])

    New Subject = SWITCH(
                    TRUE(),
                    month('Top 300 and Virt Stats'[Sent At (Your time zone)])< 10, 
    // This is first condition - if Month is less than 10, then you note I add the "-0" in your result
    
    year('Top 300 and Virt Stats'[Sent At (Your time zone)]) & "-0" & month('Top 300 and Virt Stats'[Sent At (Your time zone)]) & ": " & 'Top 300 and Virt Stats'[Subject],
    // This is the result if condition is true.
    
    year('Top 300 and Virt Stats'[Sent At (Your time zone)]) & "-" & month('Top 300 and Virt Stats'[Sent At (Your time zone)]) & ": " & 'Top 300 and Virt Stats'[Subject])
    // This is the result if no conditions are met.  That is if Month >= 10, then just use "-"

    The "//" indicates a comment, just for explanation purposes.