Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
ZoeM
Specialist
Specialist

Conditionally calculate an expression based on month

Hi Community.

I have a chart which shows planned year delivery information on a monthly basis using lines and I have a data point showing the total to be delivered this month.

I am trying to conditionally calculate so that the total only shows if the current month is in the year that the dashboard user is viewing i.e. if the user is looking at 2019 data, they should see March delivery totals, but if the user is looking at 2020 delivery information, or looks at an 18 month trend (Jan 2019 through Jun 2020) then they should still only have totals for March 2019 and not show totals for March 2020. I am using an input box for the user to determine what dates to view. I thought the below should have done the trick for the conditional show: 

Month(Today())= Year(Today())

 

Any help rendered will be appreciated. 

Labels (3)
3 Replies
sunny_talwar

You are just talking about the total? What expression and which object are you using in which you want to restrict the total? It might be easier to help if you are able to provide a sample

ZoeM
Specialist
Specialist
Author

Sorry I was off from work!

This is my expression:

Dual([Month of Year Abbreviated Name]&': '&

Count({$<[Date Type]={'VPP Dates'},Reference_Only={'No'},[Month of Year Abbreviated Name]={$(=Date(Today(),'MMM'))}>}Gateways),

Count({$<[Date Type]={'VPP Dates'},Reference_Only={'No'},[Month of Year Abbreviated Name]={$(=Date(Today(),'MMM'))}>}Gateways) )

I am thinking that if I could modify it so that if I am looking at 2019 data, I see the total for 2019 only. But when I look at 2019 and 2020 data, I am also being shown the month total for March 2020. 

Any way I can limit it to show me the monthly total for the month I am in only? Regardless of whether that month is available in other years I am looking at:

Chart.JPG

ZoeM
Specialist
Specialist
Author

I found a work around and thought to share!

I wrapped the whole equation in an If expression:

If(Year>Year(Today()),'', Dual([Month of Year Abbreviated Name]&': '&

Count({$<[Date Type]={'VPP Dates'},Reference_Only={'No'},[Month of Year Abbreviated Name]={$(=Date(Today(),'MMM'))}>}Gateways),

Count({$<[Date Type]={'VPP Dates'},Reference_Only={'No'},[Month of Year Abbreviated Name]={$(=Date(Today(),'MMM'))}>}Gateways) ) )

Works great for what I need it to do. I might have to tweak it a bit though so that if someone looks at 2018 data, Mar 2018 totals are not showing. 

Hope this will help someone