Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Dax help in SWITCH

Experts, please help me to fix the below DAX.

 
Type Description =
SWITCH(
'Accrual View'[Type]=11, "Carry Forward",
'Accrual View'[Type]=2, "Earned",
'Accrual View'[Type]=1, "Sick", 'Accrual View'[Type])

 

 

 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    1.Assume the Type columm is Number type, please try:

    Type Description = 
    SWITCH (
        TRUE (),
        'Accrual View'[Type] = 11, "Carry Forward",
        'Accrual View'[Type] = 2, "Earned",
        'Accrual View'[Type] = 1, "Sick",
        CONVERT( 'Accrual View'[Type],STRING)
    )

     

    2. Text type:

    Description =
    SWITCH ( [Type], "1", "Sick", "2", "Earned", "11", "Carry Forward", [Type] )
    

     

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

6 Replies

  • Hi,

    If you are trying to create a new column, please try something like below.

     

    Type Description =
    SWITCH (
        TRUE (),
        'Accrual View'[Type] = 11, "Carry Forward",
        'Accrual View'[Type] = 2, "Earned",
        'Accrual View'[Type] = 1, "Sick",
        'Accrual View'[Type]
    )
    
      • FreemanZ's avatar
        FreemanZ
        Super User

        hi Anonymous @what type of data do you have for the [type] column

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    1.Assume the Type columm is Number type, please try:

    Type Description = 
    SWITCH (
        TRUE (),
        'Accrual View'[Type] = 11, "Carry Forward",
        'Accrual View'[Type] = 2, "Earned",
        'Accrual View'[Type] = 1, "Sick",
        CONVERT( 'Accrual View'[Type],STRING)
    )

     

    2. Text type:

    Description =
    SWITCH ( [Type], "1", "Sick", "2", "Earned", "11", "Carry Forward", [Type] )
    

     

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.