Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Vince_CH
Creator III
Creator III

Qlik sense how to look for a first time appeared value in the year by condition

Hi All,

from a list like below, material numbers could be repeated over the years. i want to pick out the new field value first time appeared in this year, say, 2018. i tried with expression like: if(Min(year)='2018', count(DISTINCT ([Material number])), but it doesn't work out, who can give some advices? thanks. 

11.jpg

1 Solution

Accepted Solutions
Vince_CH
Creator III
Creator III
Author

Hi, just to conclude here, following are the expressoins for YTD and LYTD new materials occurency counts in KPI settings.

='YTD ' & num(Count(DISTINCT {<Year,Quarter,Month,Week,Date={"$(='>='&Date(AddYears(YearStart(Max(Date),0,7),0), 'YYYY/MM/DD') & '<='&Date(AddYears(Max(Date),0), 'YYYY/MM/DD'))"}>}
(If(Aggr(NODISTINCT Min(Date), Material)=Date, Material))),'#,##0.00K;($#,##0.00)')

&chr(13)&' LYTD ' &
num(Count(DISTINCT{<Year,Quarter,Month,Week,Date={"$(='>='&Date(AddYears(YearStart(Max(Date),0,7),-1), 'YYYY/MM/DD')
& '<='&Date(AddYears(Max(Date),-1), 'YYYY/MM/DD'))"}>}
(If(Aggr(NODISTINCT Min(Date), Material)=Date, Material)))/1000,'#,##0.00K;($#,##0.00)')

View solution in original post

12 Replies
tresesco
MVP
MVP

What would be your expected output from the sample given?
Anil_Babu_Samineni

Try this?

if(year = Max(TOTAL year),  count(DISTINCT ([Material number]))

Or

Count({<year = {$(=Max(year))}>} DISTINCT ([Material number])

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Vince_CH
Creator III
Creator III
Author

Hi Tresesco, i intend to count the brand new materials first time appeared in this year, in order to calculate the percentage of new material portion in the whole materials received.
Vince_CH
Creator III
Creator III
Author


@Anil_Babu_Samineni wrote:

Try this?

if(year = Max(TOTAL year),  count(DISTINCT ([Material number]))

Or

Count({<year = {$(=Max(year))}>} DISTINCT ([Material number])


Hi, the logic of above expression seems to be opposite to what i expected ,as it is intending to count the current year material number DISTINCT quantity, however, the same materials could be received also in past years, instead of being new materials here.

christophebrault
Specialist
Specialist

Hi,

 

In your case, I think you can use Indirect set analysis like this formula :

 

Sum({<Material=e({<Year={$(=Max(Year)-1)}>})>} Qty)

Use it in you table for Qty, and select a Year. It will excluse all Material with Qty for the previous year.

 

For several years of historic, you can use :

 

Sum({<Material=e({<Year={"<=$(=Max(Year)-1)"}>})>} Qty)

 

 

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Vince_CH
Creator III
Creator III
Author


@christophebrault wrote:

Hi,

 

In your case, I think you can use Indirect set analysis like this formula :

......

For several years of historic, you can use :

Sum({<Material=e({<Year={"<=$(=Max(Year)-1)"}>})>} Qty)

 

 


Hi Christophebraul, thanks for reply.

i intend to count DISTINCT new material numbers quantity starting to appear in this year. So the expression formula is supposed to be Count(DISTINCT{<?=e({<Year={"<=$(=Max(Year)-1)"}>})>} [Material Number]), correct? what should be on the position of question mark "?" instead?

Vince_CH
Creator III
Creator III
Author

another question is, as i use the expression in KPI expression on sub headlines, with new materials counts of YTD, also with a counterpart of LYTD, then how to write the expression text for same of LYTD?? thanks!
christophebrault
Specialist
Specialist

Then, put 

Count(DISTINCT{<[Material Number]=e({<Year={"<=$(=Max(Year)-1)"}>})>} [Material Number])

For previous year :

Count(DISTINCT{<[Material Number]=e({<Year={"<=$(=Max(Year)-2)>=$(=Max(Year))"}>})>} [Material Number])

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Vince_CH
Creator III
Creator III
Author

Hello Christophebraul, the first expression works great, thanks.

however, the second one for previous year is not matched, the calculated results is higher than my excel calculation. Also if in terms of LYTD by ending point at Dec.1st, which means for previous year, the formula shall calculate till same date, so how to write the latter expression differently?

thank you and have a nice weekend!