Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Congratulations to the new Qlik Luminary and Partner Ambassador class! Meet them here
cancel
Showing results for 
Search instead for 
Did you mean: 
mahieuphilippe
Creator
Creator

How to filter a count with a condition

Hi i have this result :

itemcodedistnumberonhandqty
1800000038127-07952.540000
1800000038127-08952.540000
1800000038127-09952.540000
1800000038127-10952.540000
1800000038127-13952.540000
1800000038127-14952.540000
1800000038127-15952.540000
1800000038127-16952.540000
1800000038127-17952.540000
1800000038127-18952.540000
1800000038127-19952.540000
1800000038127-20952.540000
1800000038128-01952.540000
1800000038128-02952.540000
1800000038128-03952.540000
1800000038128-04952.540000
1800000038128-05952.540000
1800000038128-06952.540000
1800000038128-07952.540000
1800000038128-08952.540000
1800000038128-09952.540000
1800000038128-10952.540000
1800000038128-11952.540000
1800000038128-12952.540000
1800000038128-13952.540000
1800000038128-14952.540000
1800000038128-15952.540000
1800000038128-16952.540000
1800000038128-17952.540000
1800000038128-18952.540000
1800000038128-19952.540000
1800000038128-20952.540000
1800000040132-35400.000000
1800000040132-36400.000000
1800000040132-37400.000000
1800000040132-38400.000000
1800000040132-39400.000000
1800000040132-40400.000000
1800000040133-01400.000000
1800000040133-02400.000000
1800000040133-03400.000000
1800000040133-04400.000000
1800000040133-05400.000000
1800000040133-06400.000000
1800000040133-07400.000000
1800000040133-08400.000000
1800000040133-09400.000000
1800000040133-10400.000000
1800000040133-11400.000000
1800000040133-12400.000000
1800000040133-13400.000000
1800000040133-14400.000000
1800000040133-15400.000000
1800000040133-16400.000000
1800000040133-17400.000000
1800000040133-18400.000000
1800000040133-19400.000000
1800000040133-20400.000000
1800000040133-21400.000000
1800000040133-22400.000000
1800000040133-23400.000000
1800000040133-24400.000000
1800000040133-25400.000000
1800000040133-26400.000000
1800000040133-27400.000000
1800000040133-28400.000000
1800000040133-29400.000000
1800000040133-30400.000000
1800000040133-31400.000000
1800000040133-32400.000000
1800000040133-33400.000000
1800000040133-34400.000000
1800000040133-35400.000000
1800000040133-36400.000000
1800000040133-37400.000000
1800000040133-38400.000000
1800000040133-39400.000000
1800000040133-40400.000000

 

i  want only a résult by item code with only the min of the three first number of distnumber and a count of this condition so the result is :

 

into my table graphic i use 

first colum =  dimension 

second :  Min( SubField(distnumber, '-', 1) )  (take only the min of the distnumber)

last colum  :count(
{<
distnumber = {"*$(=Aggr(Min(Left(distnumber,3))), U_CapacItemcode)*"}
>} distnumber
)

 

i have this result  (no correct, the correct is  12  for the O-71 (1800000038) , here is the total of the distnumber 127 and 128 of the 1800000038  (O-71)

mahieuphilippe_0-1763539945143.png

 

this is the correct result   how to have the good résult ?  thanks

 

180000003812712
18000000401326
Labels (1)
1 Solution

Accepted Solutions
Nagaraju_KCS
Specialist III
Specialist III

Try this 

YourData:
Load * subfield(distnumber,, '-', 1) as dist_firstnumber;
Load * Inline [
itemcode, distnumber, onhandqty                                                                                                              ........................
];

MinValue:
Load itemcode,
         Min(dist_firstnumber) as distinctValue
resident Yourdata;

chart expression
Count({<dist_firstnumber=P(distinctValue)>}itemcode)

View solution in original post

3 Replies
Nagaraju_KCS
Specialist III
Specialist III

Try this 

YourData:
Load * subfield(distnumber,, '-', 1) as dist_firstnumber;
Load * Inline [
itemcode, distnumber, onhandqty                                                                                                              ........................
];

MinValue:
Load itemcode,
         Min(dist_firstnumber) as distinctValue
resident Yourdata;

chart expression
Count({<dist_firstnumber=P(distinctValue)>}itemcode)

mahieuphilippe
Creator
Creator
Author

thanks you !!!!

thomasshellby
Contributor
Contributor

Hello 👐

 

The problem is that Min(Left(distnumber,3)) is being looked at in the way inside the set analysis. What you really want to do is find the 3 digit prefix for each 'itemcode' first and then only count the records that have that prefix. 

I would not use 'Aggr()' inside the set modifier. It is better to calculate the prefix at the itemcode dimension level and use that value for the count. 

 

Example : 

Count(
  
  Aggr(
        If(
            Left(distnumber,3) = Min(TOTAL <itemcode> Left(distnumber,3)),
            distnumber
        ),
        itemcode,
        distnumber
    )
)

Or, if your table dimension is already itemcode, a cleaner approach is:

Count(
    If(
        Left(distnumber,3) = Min(TOTAL <itemcode> Left(distnumber,3)),
        distnumber
    )
)

For 1800000038, the minimum prefix is 127. Therefore, only the 127-* records are counted:

127-07 through 127-20 = 12 records
128-* records are ignored

 

So the result, for '18000000038' should be 12. 

If you also want the column to show the minimum 'distnumber' perfix you can use: 

The key thing to remeber is that the minimum is found within each 'itemcode' not for the whole dataset. This means 'Min' is calculated for each 'itemcode'. 

Hope this will help you 👍