Forum Discussion

Prabha45's avatar
Prabha45
Helper III
3 years ago

DAX - Selected value

Hi
I wrote a measure where if is January is selected measure shows 1, february 2, so on till december.
Measure = switch(selectedvalue
                              (dim_table[month_name]),
                               "January",1,
                                "February",2)
Is it possible , if both January and February are selected, measure should show 1,2. If January,February and March are selected measure should show 1,2,3.

Thankyou

11 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Prabha45 

    if the month name column is coming from a date table the you can try. 

    CONCATENATEX ( VALUES ( 'Date'[Date].[Month] ), [Month], "," )

    However, the following shall work in all scenarios 

    CONCATENATEX (

    VALUES ( 'Table'[Month] ),

    SWITCH (

    [Month],

    "January", 1,

    "February", 2,

    etc. 

    ),

    ","

    )

     

    • Prabha45's avatar
      Prabha45
      Helper III

      Thanks that worked. I need the measure to be in integer format, but it is in Text format. I used convert to change it to integer then the output changed to 123.

      • tamerj1's avatar
        tamerj1
        Community Champion

        Prabha45 

        Cannot have an integer with delimiter. What exactly are you trying to achieve?

  • hi Prabha45 

    1) try to add a column like:

    month_number = 
    SWITCH(
        [month_name],
        "January", 1,
        "February", 2,
        "March", 3,
        "April", 4,
        "May", 5,
        "June", 6,
        "July", 7,
        "August", 8,
        "September", 9,
        "October", 10,
        "November", 11,
        12
    )

     

    2) then plot a measure like this:

    Measure = 
    CONCATENATEX(
        TableName,
        TableName[month_number],
        ","
    )

     

    it worked like:

     

    • Prabha45's avatar
      Prabha45
      Helper III

      Thanks that worked. But, the measure is in Text format. I used convert to change it to integer then the output changed to 123.