We are currently performing maintenance on Appian Community. As a result, discussions posts and replies are temporarily unavailable. We appreciate your patience.

Count function

Why does the count() function return a 1 if I pass in a null? so when I run count({null}) this returns a 1 but to me I would logically think 0. Was hoping for someone to explain this to me, Thank you.

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Appian Employee
    in reply to ericm

    The one tricky thing about the length() function though is that you may also need to consider if the variable itself is null. For instance, both of these return the same:

    length({"test"})
    count({"test"})

    The one below returns 1 for count and 0 for length:

    length({null})
    count({null})

    However, this one below actually fails when using length (and returns 1 for count()):

    length(null)
    count(null)

    So, if it's possible that the value could be null and not in a list, it's often good practice to pair your length function with a null check like this:

    a!localVariables(
      local!data: null,
      if(
        isnull(local!data),
        0,
        length(local!data)
      )
    )

Children