Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
mskusace
Creator
Creator

Count based on another Field

I would like to count a column called "ID" based on the criteria of another column "Color". The problem is, I have another table that is associated and has the same "ID", but multiple instances because it has another field called "ROLE".

I would like to count the UNIQUE "ID"s based for "Color" =  "RED". It is actually the word "RED", so text.

The table below would yield 3 and 50%. How can I do this? I am trying to use the KPI chart.

IDColor
WA13GREEN
WB14RED
WC15ORANGE
ZS15GREEN
DB09RED

 

The other associated table

IDROLEUSER
WA13MANAGERUSER1
WA13SUPERVISORUSER2
WA13ANALYSTUSER3
WB14ANALYSTUSER3
WB14MANAGERUSER4
WC15SUPERVISORUSER5
WC15MANAGERUSER6
WC15SECRETARYUSER7
ZS15MANAGERUSER4
ZS15ANALYSTUSER8
ZS15SUPERVISORUSER2
ZS15SECRETARYUSER9
DB09SECRETARYUSER10
DB09SECRETARYUSER11
DB09ANALYSTUSER12
20 Replies
abhi1693r
Contributor II
Contributor II

Also, just to clarify one PART can have multiple CUBES. Just for simplicity I have taken one for each here.

mskusace
Creator
Creator
Author

If you look at the example I posted, it has 1 part with 2 cubes associated with it. If you just do a count of "PARTS" based on that relationship and table structure, you will get a count of 4. Unless your logic has some other parameters. This is the way I am visualizing your data, which could be incorrect or maybe not the best way.

PART_IDPART
1SW1001
2DC1003
3BW1002

 

CUBES_IDCUBES
11415TV
21714DC
31516TD

 

COMBO_IDPART_IDCUBE_ID
111
212
323
43 

 

If you do a count of "COMBO_ID", then you will get 4. A new "COMBO_ID" will be created for each "PART" and "CUBE" combination.

abhi1693r
Contributor II
Contributor II

Well your solution seems like it will work, but I am really new to Qlikview.

Would you be able to guide me through the implementation?

 

Currently, I  have actually LEFT joined 2 tables to get my data. One of the tables has PART and the other table has PART and CUBES. 

mskusace
Creator
Creator
Author

If your data is lining up properly, then the implementation should be fine. Create a table visualization in Qlik and put in 2 columns, "PART" and "CUBES". If everything is as you expect, then you can just do a count of  "PART".

abhi1693r
Contributor II
Contributor II

The Solution is working for some cases but for some its acting oddly.

PARTCUBES
0MATER 
CNMMCNMC01
CNMMCNMC02
CNMMCNMC03
CNMMCNMC05
CNMMCNMC06
CNMMCNMC07
CNMMCNMC08

 

I did a count(PART) and I am getting 10. Is this due to the LEFT JOIN I setup. As the table on the LEFT had more than one entry for PART=OMATER.

 

Thanks 

Abhishek

 

mskusace
Creator
Creator
Author

Should there be more than one "0MATER" on the LEFT table? If so, are there any "CUBES" associated with any of the entries? Yes, in this case "0MATER" would all get collapsed into 1 entry for the table assuming the "CUBES" were the same for each of the "0MATER" which look blank in this case. If that is normal in your data, then we will have to do something else. Otherwise, you could just fix the data if it's an error.

 

 

abhi1693r
Contributor II
Contributor II

You are correct I have 2 'OMATER' values in the left table and hence the solution is not working comprehensively.

I do have a lot of values like 'OMATER' with blank CUBES, so should I do ?

mskusace
Creator
Creator
Author

There very well may be a better way to do this as I am no expert nor have I had the opportunity to really learn the data load script editor. I would clean the data before loading it into Qlik. I would normalize the data. You pretty much want to count the unique combination of "PART+CUBES", which becomes "COMBO_ID" essentially in my example. You could create a table with a combination of "PART+CUBES" and THEN do a distinct count on that. 

abhi1693r
Contributor II
Contributor II

 

Is there a dummy script you might have that I could refer for this implementation? or Can this be done through the UI options?

 

mskusace
Creator
Creator
Author

I would create a new Master Dimension and I would concatenate "PART" and "CUBES", so "PART&CUBES" which could be named "COMBO". Then I would keep your original table the same "PART" and "CUBES". I would create a KPI visualization that does a "COUNT(DISTINCT COMBO)".