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
NickProp28
Post Partisan
Post Partisan

Put the specific year in VAR

Dear Community,

 

I currently work out on the tooltips and chg the color according to the %.
My calculation part is correct, but I having issues on this VAR to chg the color. For example, the calc part is negative, suppose it will show red color. But this code has total up two year and change it to green. Is that possible to add on the year filter in this VAR code?

KPI color Previos19_20_A = 
VAR Green = "#056608"
VAR Red =  "#CB0525"
VAR Result = IF([Diff % previos month_2020_A] >=0, Green, Red)
Return
Result

 

Many thanks!

4 REPLIES 4
v-luwang-msft
Community Support
Community Support

Hi @NickProp28 ,

It is difficult to find the problem from the picture you provided,the dax is right. could pls provide your pbix file ? Remember to remove the confidential information.

 

 

Best Regard

Lucien Wang

amitchandak
Super User
Super User

@NickProp28 , You can add like

 

KPI color Previos19_20_A =
VAR Green = "#056608"
VAR Red = "#CB0525"
VAR Result = IF([Diff % previos month_2020_A] >=0 && Max(Table[Year]) ="20202", Green, Red)
Return
Result

 

refer to My video : https://www.youtube.com/watch?v=RqBb5eBf_I4

 

other examples

 

 

Colour =
SWITCH(TRUE(),
max('Table'[Month Year]) = "Jan-2020", "red",
Max('Table'[Month Year]) < "Feb-2020", "orange",
//keep on adding
"green")

Dear @amitchandak ,

 

I had follow your code, but it does not work.

NickProp28_0-1614060532686.png

Please kindly advice.

@NickProp28 , I typically use TI for this with slicer of date on current month or year

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

diff = [MTD Sales]-[last MTD Sales]
diff % = divide([MTD Sales]-[last MTD Sales],[last MTD Sales]) // Conditional formatting on this

 

 

for year

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ]) // Use in conditional formatting

 

 

Default Date : https://www.youtube.com/watch?v=hfn05preQYA

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.