Due to privacy, I can’t create a sample of this data. I am trying to change the first sum in this calculation to a distinct_count. I am looking to calculate the distinct count of alertid records that begin with the letters “ins”. From there, I want to subtract the rest of the results below it (and that math is working). I believe something is wrong with my distinct_count syntax.
sum(ifelse(contains(alertid, ‘ins’), 1, 0)) -
sum(ifelse(
contains(resultcode, ‘CIN’) or contains(resultcode, ‘COK’) or contains(resultcode, ‘CON’)
or contains(resultcode, ‘ICIN’) or contains(resultcode, ‘ICOK’) or contains(resultcode, ‘ICON’)
or contains(resultcode, ‘RAA’) or contains(resultcode, ‘RAB’)
or contains(resultcode, ‘IRAA’) or contains(resultcode, ‘IRAB’)
or contains(resultcode, ‘XF’) or contains(resultcode, ‘IXF’), 1, 0))
For the distinct_count, since the formula you wrote is returning 1, all occurences are counted. Can you try using distinct_count(ifelse(contains(alertid,‘ins’),alertid,NULL)) ? This will count distinct instead of count all occurence(current formula is returning count ).
Thanks @prantika_sinha
The distinct_count part you gave me seems to work. Now when I try to make it into a formula, it give me a syntax error. Can you tell me if I am doing this inorrectly?
sum(ifelse(
distinct_count(ifelse(contains(alertid,‘ins’),alertid,NULL)) -
sum(ifelse(contains(resultcode, ‘TCS’) or contains(resultcode, ‘EQ1’) or contains(resultcode, ‘COK’) or contains({resultcode}, ‘ICOK’)
or contains(resultcode, ‘X’) or contains(resultcode, ‘IX’), 1, 0))
distinct_count(ifelse(contains(alertid,‘ins’),alertid,NULL)) -
sum(ifelse(contains(resultcode, ‘TCS’) or contains(resultcode, ‘EQ1’) or contains(resultcode, ‘COK’) or contains({resultcode}, ‘ICOK’)
or contains(resultcode, ‘X’) or contains(resultcode, ‘IX’), 1, 0))