Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AlanP514
Helper V
Helper V

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

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @AlanP514 ,

 

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

(1) This is my test data.  

vtangjiemsft_0-1677466986625.png

(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.

vtangjiemsft_1-1677467361567.png

(5) Then the result is as follows.

vtangjiemsft_2-1677467394527.png

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. 

View solution in original post

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @AlanP514 ,

 

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

(1) This is my test data.  

vtangjiemsft_0-1677466986625.png

(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.

vtangjiemsft_1-1677467361567.png

(5) Then the result is as follows.

vtangjiemsft_2-1677467394527.png

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. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.