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

Announcements
January 14th - Discover the Trends Shaping AI in 2026: Register Here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Subha
Contributor
Contributor

Error in Expression

Hello All,

 

Could anyone please help me to solve the below expression?

 


Count({<Month=,FiscalMonth=,FiscalMonthName=,Year=,Date={">=$(=Date(AddYears(YearStart(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))
<=$(=Date(AddYears(Yearend(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))"},
Year=,FiscalYear,
Distinct In_PersonID)

Labels (2)
2 Solutions

Accepted Solutions
marcus_sommer

Detecting logically and/or syntactically errors within long and complex expressions is always quite hard. Therefore you should try to avoid it from the beginning and starting very simple, like:

count(Field) and then count({< SingleSetStatement >} Field)

and so on. If they work you could add the next step on complexity to it. It may look a bit cumbersome but it's quite common and a best practice approach - at least for all new/changed views - because beside getting a result you need always to verify that the results are correct and the simplest method is to calculate the intermediate steps in parallel and after they are working to merge them and checking it again.

Beside this your expression missed multiple brackets and it looked as if there were typos, too because I see FiscalYear and fiscalYear. Further just remove the date() which aren't needed to shorten the expression.

IMO you should also change the set analysis conditions itself - not querying dates else years or periods or a continuing period-counter because it would simplify the approach. There is even more possible by creating appropriate flags for the current/previous years/periods within the master-calendar. Here is a lot of background to it:

How to use - Master-Calendar and Date-Values - Qlik Community - 1495741

- Marcus

View solution in original post

RafaelBarrios
Partner - Specialist
Partner - Specialist

Hi @Subha 

The only weird thing I can see is that you are not closing the set statement {< >} 

Haven’t try it but you can try

Count(
{<

Month=,FiscalMonth=,FiscalMonthName=,Year=,Date={">=$(=Date(AddYears(YearStart(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))
<=$(=Date(AddYears(Yearend(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))"}

>}
Distinct In_PersonID)

 

I also remove Year=,FiscalYear, as you where doing that twice.

 

best,

 

View solution in original post

7 Replies
Mark_Little
Luminary
Luminary

HI @Subha 

Not sure what you are trying to do here but your set expression is not enclosed correctly. 

You close it before the end you the set you are trying to analyse, might be even more problems

Count({<Month=,FiscalMonth=,FiscalMonthName=,Year=,Date={">=$(=Date(AddYears(YearStart(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))
<=$(=Date(AddYears(Yearend(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))"},
Year=,FiscalYear,
Distinct In_PersonID)

Subha
Contributor
Contributor
Author

Hi @Mark_Little 

 

I am trying to do a set analysis for comparing previous year

please see below the full statement

 

=if((GetSelectedCount(FiscalYear)>0 AND GetSelectedCount(Year)=0)
,
Count({<Month=,FiscalMonth=,FiscalMonthName=,Year=,Date={">=$(=Date(AddYears(YearStart(Date(Max({<FiscalYear={"=$(=Max(FiscalYear)-1)"}>}Date),'MMM-YYYY'),0,4),-1),'DD-MM-YYYY'))
<=$(=Date(AddYears(Yearend(Date(Max({<fiscalYear={"=$(=Max(FiscalYear)-1)"}>}Date),'MMM-YYYY'),0,4),-1),'MMM-YYYY'))"},
Year=,FiscalYear,
distinct In_PersonID),

if((GetSelectedCount(FiscalYear)=0 AND GetSelectedCount(Year)>0)
,

Count({<Month=,FiscalMonth=,FiscalMonthName=,FiscalYear=,
Date={">=$(=Date(AddYears(Date(YearStart(Max({<Year={"$(=Max(Year))"}>}Date)),'DD-MM-YYYY'),-1),'DD-MM-YYYY'))
<=$(=Date(Addyears(Max(Date),-1),'DD-MM-YYYY'))"},FiscalYear,Year,distinct In_PersonID),


Count({<Date={">=$(=Date(AddYears(date((min({<Year={"$(=Max(Year))"}>}Date)),'DD-MM-YYYY'),-1),'DD-MM-YYYY') )<=$(=Date(AddYears(date((max({<Year={"$(=Max(Year))"}>}Date)),'DD-MM-YYYY'),-1),'DD-MM-YYYY'))"},Year=,Month,distinct In_PersonID)

 

marcus_sommer

Beside the already mentioned missing brackets to close the set analysis (parts) - the last brackets before Distinct is also not set - you should simplify the statement, for example by removing the multiple date() functions because you compares with >= and <= against numerical values and there the formatting is irrelevant.

- Marcus

Subha
Contributor
Contributor
Author

Could anyone please help me on how to rewrite the formula?

marcus_sommer

Detecting logically and/or syntactically errors within long and complex expressions is always quite hard. Therefore you should try to avoid it from the beginning and starting very simple, like:

count(Field) and then count({< SingleSetStatement >} Field)

and so on. If they work you could add the next step on complexity to it. It may look a bit cumbersome but it's quite common and a best practice approach - at least for all new/changed views - because beside getting a result you need always to verify that the results are correct and the simplest method is to calculate the intermediate steps in parallel and after they are working to merge them and checking it again.

Beside this your expression missed multiple brackets and it looked as if there were typos, too because I see FiscalYear and fiscalYear. Further just remove the date() which aren't needed to shorten the expression.

IMO you should also change the set analysis conditions itself - not querying dates else years or periods or a continuing period-counter because it would simplify the approach. There is even more possible by creating appropriate flags for the current/previous years/periods within the master-calendar. Here is a lot of background to it:

How to use - Master-Calendar and Date-Values - Qlik Community - 1495741

- Marcus

RafaelBarrios
Partner - Specialist
Partner - Specialist

Hi @Subha 

The only weird thing I can see is that you are not closing the set statement {< >} 

Haven’t try it but you can try

Count(
{<

Month=,FiscalMonth=,FiscalMonthName=,Year=,Date={">=$(=Date(AddYears(YearStart(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))
<=$(=Date(AddYears(Yearend(Date(Max({<FiscalYear={"=$(=Max(FiscalYearNum)-1)"}>}Date),'DD-MM-YYYY'),0,4),-1),'DD-MM-YYYY'))"}

>}
Distinct In_PersonID)

 

I also remove Year=,FiscalYear, as you where doing that twice.

 

best,

 

Subha
Contributor
Contributor
Author

Thank you all, i have simplified the set statement and now it is working.