Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
RC987654321
Contributor
Contributor

Calculated value based on multiple rows

Hello, I believe this is a very simple question, but haven't been able to find a good solution:

I have a loaded resident table with two columns, a Product and the results of a Quality Test.

In the load script, I want to create a second table with the Product, and a calculated field that checks if any Quality Tests have value "Fail" then apply value "Bad", otherwise apply value "Good"

Resident Table:

ProductQuality Test
Product APass
Product AFail
Product APass
Product BPass
Product BPass
Product BPass

 

This is the secondary table I am trying to produce:

ProductProduct Quality
Product ABad
Product BGood

 

Thank you in advance for your help

1 Solution

Accepted Solutions
PrashantSangle

Hi,

use FindOneOf()

try below script
Test:
Load Product,
if(FindOneOf(Concat(DISTINCT Quality_Test),'F')>0,'Bad','Good') as Flag,
Concat(DISTINCT Quality_Test) as new_test_result
Inline [
Product, Quality_Test
Product A, Pass
Product A, Fail
Product A, Pass
Product B, Pass
Product B, Pass
Product B, Pass
]
Group By Product
;

Regards,
Prashant Sangle
Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

View solution in original post

3 Replies
PrashantSangle

Hi,

use FindOneOf()

try below script
Test:
Load Product,
if(FindOneOf(Concat(DISTINCT Quality_Test),'F')>0,'Bad','Good') as Flag,
Concat(DISTINCT Quality_Test) as new_test_result
Inline [
Product, Quality_Test
Product A, Pass
Product A, Fail
Product A, Pass
Product B, Pass
Product B, Pass
Product B, Pass
]
Group By Product
;

Regards,
Prashant Sangle
Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
jonathandienst
Partner - Champion III
Partner - Champion III

Chart or table with Product a dimension, and 

If(Count({<[Quality Test] = {'Fail'}>} Product) > 0, 'Bad', 'Good')

as a measure

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
asinha1991
Creator III
Creator III

There are two ways I can think of, both utilizing preceding load.

 

A. using concat..concat will aggregate all values for a product separated by delimiter. You can use something like this

 

Final Test:

Load Product, if(wildmatch(temp_agg,'*Fail*'),'Bad','Good') as [Product quality];

Load  Product, concat([Quality Test],',') as temp_agg

Resident Table group by Product;

 

B.  you can create a binary indicator, this is also helpful if you want to mark it bad if certain percentage of test fails.

//if any one test fails 

Final Test:

Load Product, if(sum(temp_ind)>0,'Bad','Good') as [Product Quality]

group by Product;

Load  Product, if(match([Quality Test],'Fail'),1,0) as temp_ind

Resident Table ;

 

//if more than 50% fails

Load Product, if(sum(temp_ind)/count(temp_ind)>0.5,'Bad','Good') as [Product Quality]

group by Product;

Load  Product, if(match([Quality Test],'Fail'),1,0) as temp_ind

Resident Table ;