Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
April 13–15 - Dare to Unleash a New Professional You at Qlik Connect 2026: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
surikishore7517
Contributor II
Contributor II

Color code expression in Qlik Sense Button

After making changes of Variables definition we are encountering with color code on Buttons based on these variables. Please find the details below.
vRef1 = Max (Date) for current month and vRef2 = Max (Date,2) for previous month
In the Variable Input, under DROPDOWN option we are using the DYNAMIC value as =concat(distinct [Date MMM YY],'|', -[Date MMM YY])
(Where Date MMM YY is the field created in script by using Date.)
Now the issue is that we are using 4 Buttons for Previous Month/Quarter/Half Year/Year and added variable =Date(Addmonths(Date#('$(vRefMth1)', 'MMM YY'),-1),'MMM YY') for each Button (depends on Month/Quarter/half Year/Year).

Here each button should change the color based on button selection.

Currently using the color code expression is

if(
(Year('$(vRefMth1)') * 12 + Month('$(vRefMth1)')) - (Year('$(vRefMth2)') * 12 + Month('$(vRefMth2)')) = 1,
RGB(229,155,157),
RGB(232,232,232)
)

By using this color code expression, the color is not applying as expected upon Button selection.

Please check and provide the corrected color code expression

Thanks,
S Kishore

Labels (1)
1 Solution

Accepted Solutions
surikishore7517
Contributor II
Contributor II
Author

Hi Everyone,

My issue resolved by using the below expression

=if((year(Date#('$(vRefMth1)','MMM YY'))*12 + month(Date#('$(vRefMth1)','MMM YY'))) - (year(Date#('$(vRefMth2)','MMM YY'))*12 + month(Date#('$(vRefMth2)','MMM YY'))) = 1
,
vRed
,
RGB(232,232,232)
)



Thanks

S Kishore

View solution in original post

3 Replies
clairehar557ris
Contributor
Contributor

Hello, @surikishore7517 

The issue is that your current code just checks if a one-month gap exists between two variables, rather than checking if the variable actually matches that specific button's "goal." To make the color change when kdealer plus clicked, the color expression needs to ask: "Is the current value of my variable equal to the date this button is supposed to represent?" Use the expression if('$(vRefMth1)' = Date(AddMonths(Date#('$(vRefMth2)', 'MMM YY'), -1), 'MMM YY'), RGB(229,155,157), RGB(232,232,232)) for the Month button, and simply swap the -1 for -3 (Quarter), -6 (Half Year), or -12 (Year) for the others. This ensures the button only lights up when the active selection matches that button's specific timeframe.

surikishore7517
Contributor II
Contributor II
Author

Hi @clairehar557ris ,

 

Thank you so much for the quick response.

Used your solution, still the color is not affected. 

Thanks

S Kishore

surikishore7517
Contributor II
Contributor II
Author

Hi Everyone,

My issue resolved by using the below expression

=if((year(Date#('$(vRefMth1)','MMM YY'))*12 + month(Date#('$(vRefMth1)','MMM YY'))) - (year(Date#('$(vRefMth2)','MMM YY'))*12 + month(Date#('$(vRefMth2)','MMM YY'))) = 1
,
vRed
,
RGB(232,232,232)
)



Thanks

S Kishore