Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
richard24best
Creator II
Creator II

Percentage Calcuation with if condition

Hi All,

I am having an issue to calculate percentage rate, tried the below getting error.

Please assist

count(distinct{<[Sub Type]={'Cash'}>,{<Month_Year>} [ID]) / sum({$<[Status]={'Matched'}>}[Transfer_ID]))

want to calculate count of distinct ID when [Sub Type]={'Cash'} for each Month_Year divide by sum(Transfer ID) when Status = Matched.

Thank you,

Richard

 

Labels (1)
1 Solution

Accepted Solutions
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @richard24best ,

The first thing you need to do is always ensure that your brackets match up,  you have mismatches with {, ) and <.

The Month_Year part of the first set statement is incorrect, as it doesn't have an = sign with it.

If you are trying to get the percentage for each month then the Month_Year should be the dimension in the table or chart, not part of the expression.

To fix the expression so it is valid, you need:

count(distinct {<[Sub Type]={'Cash'}>} [ID]) / sum({<Status={'Matched'}>}[Transfer_ID])

If you want to have a total across all months, but counting the ID in each month it falls you need to use an AGGR statement. Suggest you look up how these work, but in simple terms they allow you to create a virtual table based on a field or number of fields and then perform another operation over that result set.

The syntax would be:

sum(aggr(count(distinct {<[Sub Type]={'Cash'}>} [ID]), Month_Year)) / sum({<Status={'Matched'}>}[Transfer_ID])

Hope that helps.

Steve

View solution in original post

2 Replies
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @richard24best ,

The first thing you need to do is always ensure that your brackets match up,  you have mismatches with {, ) and <.

The Month_Year part of the first set statement is incorrect, as it doesn't have an = sign with it.

If you are trying to get the percentage for each month then the Month_Year should be the dimension in the table or chart, not part of the expression.

To fix the expression so it is valid, you need:

count(distinct {<[Sub Type]={'Cash'}>} [ID]) / sum({<Status={'Matched'}>}[Transfer_ID])

If you want to have a total across all months, but counting the ID in each month it falls you need to use an AGGR statement. Suggest you look up how these work, but in simple terms they allow you to create a virtual table based on a field or number of fields and then perform another operation over that result set.

The syntax would be:

sum(aggr(count(distinct {<[Sub Type]={'Cash'}>} [ID]), Month_Year)) / sum({<Status={'Matched'}>}[Transfer_ID])

Hope that helps.

Steve

richard24best
Creator II
Creator II
Author

Thank you Steve for your explanation and support.

Regards,

Richard