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

Count Ids above Average

I have the following sample table where I am required to calculate the average time for each parameter.

For ids where date closed is populated

Time = Date Closed – Date Open

For ids where date closed is blank

Time = max(Date Updated) – Date Open

 

ParametersIDDate OpenDate ClosedDate Updated
TemperatureAB5/13/201712/16/201712/18/2017
Wind forceAD6/8/2018 10/10/2018
Wind forceAD6/8/2018 11/10/2018
HumidityAC3/10/20181/2/20192/7/2019
TemperatureAG8/15/2018 11/20/2018
HumidityAH5/3/2018 8/19/2018
HumidityAH5/3/2018 9/2/2018
Wind forceAO7/23/2018 7/29/2018

 

I am required to find the average time taken for each parameter and the no. of ids which are above the average time. My final Table should look something like this:

CasesAverage TimeNo of IDs Above Average
Temperature1571
Humidity210.51
Wind force811

 

 

 

 

 

 

1 Solution

Accepted Solutions
sunny_talwar

Try this for Count of IDs

Count(Aggr(
	If(Avg(TOTAL <Parameters> Aggr(If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), Parameters, ID)) > If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), ID)
, ID, Parameters))

or

Count(DISTINCT Aggr(
	If(Avg(TOTAL <Parameters> Aggr(If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), Parameters, ID)) > If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), ID)
, ID, Parameters))

View solution in original post

4 Replies
sunny_talwar

May be try this

Avg(Aggr(
If(Len(Trim([Date Closed])) > 0,
([Date Closed] - [Date Open]),
(Max(TOTAL <ID> [Date Updated]) - [Date Open])
)
, Parameters, ID))
Wilbert
Contributor
Contributor
Author

Hi Sunny,

Thanks for the response. However, I am looking to count the number of  IDs against each parameter that are above the average calculated (last column of my result table). 

sunny_talwar

Try this for Count of IDs

Count(Aggr(
	If(Avg(TOTAL <Parameters> Aggr(If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), Parameters, ID)) > If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), ID)
, ID, Parameters))

or

Count(DISTINCT Aggr(
	If(Avg(TOTAL <Parameters> Aggr(If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), Parameters, ID)) > If(Len(Trim([Date Closed])) > 0, ([Date Closed] - [Date Open]), (Max(TOTAL <ID> [Date Updated]) - [Date Open])), ID)
, ID, Parameters))
Wilbert
Contributor
Contributor
Author

Thanks  Sunny