Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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)
I didn't follow you. Can you provide more information. How you are calc. 3 and 2 for A & B
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.
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)
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?