Skip to main content
Announcements
Happy New Year! Cheers to another year of collaboration, connections and success.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count number of same value clusters

I want to count the number of clusters having a certain value. Ideally as a chart expression but if that's not possible then the load script would be fine.

Ex if I have a table with a Field:

A

A

A

B

B

B

B

A

A

B

B

B

A

I want to get:

A: 3

B: 2

1 Solution

Accepted Solutions
vishsaggi
Champion III
Champion III

Try this?

TableA:

LOAD *, if(FieldA = Previous(FieldA), Peek(Rank), RowNo()) as Rank  INLINE [

FieldA

A

A

A

B

B

B

B

A

A

B

B

B

A

];

Add a straight table.

Dim: FieldA

Expr: Count(Distinct Rank)

View solution in original post

4 Replies
Anil_Babu_Samineni

I didn't follow you. Can you provide more information. How you are calc. 3 and 2 for A & B

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Not applicable
Author

A cluster in this case is considered a series of continuous values, and the next cluster starts when the field value changes:

first cluster: AAA (label A)

Second cluster: BBBB (label B)

Third cluster: AA (label A)

Fourth cluster: BBB (label B)

Fifth cluster: A (label A)

As you can see there are three clusters with type A, and two  types B. So instead of counting each single row, I want to see how many "blocks" there are for each type. A simple aggregation does not work in this case. I could add a third cluster below, let's say CCCCCC. Doing so would generate the result:

A: 3

B: 2

C: 1

Hope this helps clarify.

vishsaggi
Champion III
Champion III

Try this?

TableA:

LOAD *, if(FieldA = Previous(FieldA), Peek(Rank), RowNo()) as Rank  INLINE [

FieldA

A

A

A

B

B

B

B

A

A

B

B

B

A

];

Add a straight table.

Dim: FieldA

Expr: Count(Distinct Rank)

Not applicable
Author

Looks great thanks!

Is there any way to do this directly in the straight table expression since FieldA is already loaded, without doing another load in the script?