Skip to main content
vinodn0005
April 22, 2022
Question

Count distinct elements in an array

  • April 22, 2022
  • 2 replies
  • 0 views

I have a requirement where I have to find the distinct value in the grid column and display it 

Any suggestion

2 replies

harshitb6843
April 22, 2022

union() the array by itself and then use the count() function

andrewh0007
April 22, 2022

Give this a go.

a!localVariables(
  local!values: {1,2,5,33,8,6,4,3,4,5,32,3,4,33,2,45,6,7,89,0,87,6,45,6345,35,6534,35,65,43,1,3,4,2},
  local!distinctValues: union(
    local!values,
    local!values
  ),
  local!countOfDistinctValues: if(
    a!isNullOrEmpty(local!distinctValues),
    0,
    length(local!distinctValues)
  ),
  {
    values: local!values,
    distinctValues: local!distinctValues,
    countOfDistinctValues: local!countOfDistinctValues
  }
)