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

Announcements
April 13–15 - Dare to Unleash a New Professional You at Qlik Connect 2026: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

SUM Distinct

I have a fact table containing patient data. For example, patient is treated for Disease A , Disease B or combination AB. A patient might have multiple entries in a fact table among different Disease group. Now, when I sum on patient for an individual group I get the total from all three groups. How can I tell QV to do a distinct on a patient. If patient has already included in a count for one group DONT count it another time.

Please let me know if you need additional info.

4 Replies
johnw
Champion III
Champion III

I'm not sure I understand the question.

If you don't have disease as a dimension in your chart, count(distinct patient) will only count the patients once. If you DO have disease as a dimension in your chart, WHICH disease did you want to include the patient under if they're been treated for multiple diseases? QlikView isn't making the decision for you, which is why you'll see the patient counted under each disease. However, if you do a total for the diseases, it will then count correctly again (unless you select sum of rows).

Not applicable
Author

You can use set expressions to achieve this:

count({<disease={'A'}>} patient)

Not applicable
Author

John You understood the question right. I have disease as a dimesion in my table chart. I have given a group_code for a patient and disease where patient belongs to. If patient has code A for a particular date, and he occurs under code B on the same date I want to exclude one. I know its hard for you to understand. I will share the app soon.
Not applicable
Author

How would you write the following SQL statement as a QV expression. My fact table is MONTH_PTNT_CNT which has data at regimen level(a lowest regimen level = RGMN_NBR). Another table is REGIMEN_GRP table which states what regimen belongs to which group. It is highly likely that a regimen can belong to more than one regimen_group Or you can say that some regimen_nbr will share parents. In SQL you can easily identify by using IN keyword as stated in the query.

select

sum(TOT_PTNT_CNT)

from MONTH_PTNT_CNT

where s_gid=21



and rgmn_nbr IN (select rgmn_nbr from REGIMEN_GRP where s_gid=21 and rgmn_grp_gid = 15)



and MTH_INT=200907



and dg_combo_nbr=1