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

Subtract counts if both condition are met /same Serialnumber

Hello,

I have following table:

SerialnumberStatus
1111B
1111M
2222B
2222M
3333B
3333M
5432B
1234B

 

I want to count the serialnumbers with status 'B' . Only in case the serialnumber already exist with status 'M' it should be deducted from the first count.

like that: count({$<Status={B}>}serialnumber)- count({$<Status={M}, (serialnumber of  B= seralnumber of M>}serialnumber) 

Is that better solve with If-Statement? can you give me example in if and in set analysis please. 

I hope I explained my problem well. 

Thank you in advance.

4 Solutions

Accepted Solutions
PriyankaShivhare
Creator II
Creator II

Hi,

I am not sure about your requirement but to get the equal serial no  for different status. u need to whrite this:

serialnumber of  B= seralnumber of M: 

count({<Serialnumber=p({<Status={'B'}>})>*<Serialnumber=p({<Status={'M'}>}) >}Distinct Serialnumber)

and your full expression will be:

count({$<Status={B}>}Serialnumber)- count({$<Status={M},Serialnumber=p({<Status={'B'}>})>*<Serialnumber=p({<Status={'M'}>})>} Distinct Serialnumber)

Hope this helps

 

Thanks,

Priyanka

View solution in original post

Taoufiq_Zarra

@Applicable88  are you looking for ?

=count({<Status={'B'},Serialnumber={"= count({<Status={'M'}>}Status)>0"}>} Serialnumber)

 

output

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

sunny_talwar

@Applicable88  try this

 

Count(DISTINCT {$<serialnumber = {"=Count(DISTINCT {<Status = {'M', 'B'}>} Status) = 2"}>} serialnumber)

 

View solution in original post

Taoufiq_Zarra

@Applicable88  if its the same logic you need:

=sum({<Status={'B'},Serialnumber={"= count({<Status={'M'}>} Status)>0"}>} Value)

and

=sum({<Status={'B'},Serialnumber={"= count({<Status={'M'}>} Status)>0"}>} Value)

if not can you share also the expected output from the attached sample ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

11 Replies
sunny_talwar

@Applicable88 So, you only want to count 5432 and 1234 in the example above? Try this may be

Count({$<serialnumber = E({<Status = {'M'}>})>} serialnumber)

 

PriyankaShivhare
Creator II
Creator II

Hi,

I am not sure about your requirement but to get the equal serial no  for different status. u need to whrite this:

serialnumber of  B= seralnumber of M: 

count({<Serialnumber=p({<Status={'B'}>})>*<Serialnumber=p({<Status={'M'}>}) >}Distinct Serialnumber)

and your full expression will be:

count({$<Status={B}>}Serialnumber)- count({$<Status={M},Serialnumber=p({<Status={'B'}>})>*<Serialnumber=p({<Status={'M'}>})>} Distinct Serialnumber)

Hope this helps

 

Thanks,

Priyanka

Applicable88
Creator III
Creator III
Author

I want exactly the opposite. I want to count the serialnumbers,  where the serialnumbers exist two times , one with status =B and the other one with status =M.

Applicable88
Creator III
Creator III
Author

Hello @PriyankaShivhare ,

now I understand. 

Great apporach with the element functions p and e.

Thank you.

Taoufiq_Zarra

@Applicable88  are you looking for ?

=count({<Status={'B'},Serialnumber={"= count({<Status={'M'}>}Status)>0"}>} Serialnumber)

 

output

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
sunny_talwar

@Applicable88  try this

 

Count(DISTINCT {$<serialnumber = {"=Count(DISTINCT {<Status = {'M', 'B'}>} Status) = 2"}>} serialnumber)

 

Applicable88
Creator III
Creator III
Author

Hello @Taoufiq_Zarra ,

it works so far very good with the serial numbers that needed to be count. 

In my actual table I also need to do the same thing with the column  "Values" and "Positions" in the same table.

These needs to be summed up not counted.

sum({$<Status={'VER'},Value={"= sum({1<Status={'A'}>}Status)>0"}>} Value)

neither position:

sum({$<Status={'VER'},Position={"= sum({1<Status={'A'}>}Status)>0"}>} Position)

 

The same structure doesn' t work to sum up these two values. I get way to high numbers. Do you have an idea?


Thanks so far!

Taoufiq_Zarra

@Applicable88  you remove 1 in 1<.. (Set analysis) if I understood correctly

or can you share a sample data with values and position and the expected output ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Applicable88
Creator III
Creator III
Author

Serialnumber Status Positions Value
1111 B 10 1000
1111 M 10 1000
2222 B 45 8000
2222 M 45 8000
3333 B 70 210
3333 M 70 210
5432 B 40 55
1234 B 25 33