Forum Discussion

AlanP514's avatar
AlanP514
Icon for Post Patron rankPost Patron
3 years ago
Solved

Dax for Dynamic color

Here i need to Create one dax measure or calculated column

 

Scenario in the year slicer i have Year starting from 2022

 

I need to show selected year and previous year values

So if i select 2022 frm year slicer

Selected year is 2022 and previous year is 2021

 

So i need to create one measure for showing both different color

 

If i select 2022 (Selecting year) this Selecting year should show in this color code #315989

 

If i select 2022 so previous year is 2021 so dont have data for 2021 so i need to show it in this color #666666

 

 

 

 

Note : it should be dynamic note static

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi AlanP514 ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data.  

    (2) We can create a table.

     

    Table 2 = SELECTCOLUMNS('Table',"slicer",YEAR('Table'[date]))

     

    (3)We can create a measure. 

     

    Measure = 
    var a=SELECTEDVALUE('Table 2'[slicer])
    var b=YEAR(MAX('Table'[date]))
    var c=YEAR(MAX('Table'[date]))+1
    return SWITCH(TRUE(),
     a=b ,1,
    c=a,2,
      0)

     

    (4)Set the conditional formatting as shown in the following figure.

    (5) Then the result is as follows.

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi AlanP514 ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data.  

    (2) We can create a table.

     

    Table 2 = SELECTCOLUMNS('Table',"slicer",YEAR('Table'[date]))

     

    (3)We can create a measure. 

     

    Measure = 
    var a=SELECTEDVALUE('Table 2'[slicer])
    var b=YEAR(MAX('Table'[date]))
    var c=YEAR(MAX('Table'[date]))+1
    return SWITCH(TRUE(),
     a=b ,1,
    c=a,2,
      0)

     

    (4)Set the conditional formatting as shown in the following figure.

    (5) Then the result is as follows.

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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