Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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)
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
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,
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)
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)
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
Could anyone please help me on how to rewrite the formula?
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
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,
Thank you all, i have simplified the set statement and now it is working.