Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Rabia_Taimur
Contributor III
Contributor III

Showing YTD Stats in KPI graph

Hi i am trying to show annual promotion count in KPI graph. If nothing is selected, graph should show YTD stats, else the number should be updated as per the fiscal year selected.

The below code shows the YTD stats but doesn't show the stats as per filter selection:

=if(
GetSelectedCount([Promotion_dt.Fisc.Year])=0,
Count(Distinct if(Promotion_dt>=AddMonths(date(yearstart(today(),0,7)),0),Emp_No)),
count(distinct Emp_No)
)

When nothing is selected YTD, correct YTD number is returned

Rabia_Taimur_2-1716353492171.png

On filter selection, this becomes 'Zero'

Rabia_Taimur_3-1716353543297.png

 

The below code shows the stats as per filter selection, but count the whole employee base when nothing is selected:

=if(Promotion_dt>=AddMonths(date(yearstart(today(),0,7)),0) ,count(distinct Emp_No),count(distinct Emp_No))

Nothing selected, so number should be 160 for YTD promotions

Rabia_Taimur_0-1716353356327.png

Working fine for filter selections

Rabia_Taimur_1-1716353414269.png

 

Labels (1)
4 Replies
Chanty4u
MVP
MVP

Try this 

Count(Distinct

    If(

        GetSelectedCount([Promotion_dt.Fisc.Year])=0,

        If(Promotion_dt>=AddMonths(date(yearstart(today(),0,7)),0), Emp_No),

        Emp_No

 

  )

)

Rabia_Taimur
Contributor III
Contributor III
Author

Thank you for your response but its still same. KPI visual doesn't update with filter selection

Sayed_Mannan
Creator II
Creator II

Hi, try this

=If(
    GetSelectedCount([Promotion_dt.Fisc.Year]) = 0,
    Count(Distinct {<Promotion_dt = {"=Promotion_dt >= AddMonths(YearStart(Today(), 0, 7), 0)"}>} Emp_No),
    Count(Distinct Emp_No)
)

 

Rabia_Taimur
Contributor III
Contributor III
Author

I have found the solution, GetSelectedCount wasn't working with the formula being used behind the filter to limit values to past 4 years. I was using below formula:

IF(Promotion_dt>=AddYears(date(yearstart(today(),0,7)),-3),[Promotion_dt.Fisc.Year])

If i use only

Promotion_dt.Fisc.Year, it works

If anyone can please explain why it doesn't work and can I limit the values shown in filter without effecting the functionality of GetSelectedCount(), i'll be greatful