Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to count records by group with condition

Hi, I would like to create a calculated dimension to be able to create a pie graph later on, based on the following:

I have this table:

IDGROUPTYPE
1AX
2AX
3AY
4AY
5BX
6BY
7CX
8CX
9CY

I need to count ID's where TYPE = X and create a straight table like this:

GROUPVALID
A2
B1
C2

So I could create a calculated dimension:

if (valid>1, 'OK', 'Not OK')

and create a pie chart using the calculated dimension. Based on the example, the pie will have 2 slices where 'OK' represents 66.6% and 'Not OK', 33.3%

Many thanks in advance for your help!

Cheers,

Vinia

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Create a Pie Chart

Dimension (Use Calculated Dimension)

=Aggr(IF(COUNT({<TYPE = {'X'}>}DISTINCT ID)>1,'OK','NOT OK'),GROUP)

Expression

COUNT(DISTINCT GROUP)/COUNT(TOTAL DISTINCT GROUP)

Tick Values on Data Points

Go to Number Tab

Integer

Tick Show in Percent (%)

View solution in original post

4 Replies
sunny_talwar

May be like attached:

Capture.PNG

MK_QSL
MVP
MVP

Create a Pie Chart

Dimension (Use Calculated Dimension)

=Aggr(IF(COUNT({<TYPE = {'X'}>}DISTINCT ID)>1,'OK','NOT OK'),GROUP)

Expression

COUNT(DISTINCT GROUP)/COUNT(TOTAL DISTINCT GROUP)

Tick Values on Data Points

Go to Number Tab

Integer

Tick Show in Percent (%)

Not applicable
Author

Thank you, Sunny and Manish.

How do I create the straight table as I have mentioned in my original post without having to go to the script editor. Is there a way to do that using an expression?

MK_QSL
MVP
MVP

My method is for front end only. You don't need to work anything inside script.