2 Replies Latest reply: Jun 19, 2018 1:49 PM by David Forest RSS

    Age calculation

    Carlos Bondoc

      Hello

       

      Need help calculating average age using this expression:

       

      Average(Age (service_date, entry date) where

      Service Name = "Service" and Entry Provider = "Provider1"

        • Re: Age calculation
          William Fu

          Is age the difference between service_date and entry_date?

           

          Try creating a Age field in your load script (something like (service_date - entry_date) AS Age

           

          Then use the Age field in your average:

           

          Avg({$<ServiceName={'Service'}, EntryProvider={'Provider1'}>} Age)

          • Re: Age calculation
            David Forest

            the age function only returns years.

            As William said, you could put the difference as a new field, but you can also just do it in an expression:

            Avg({$<ServiceName={'Service'}, EntryProvider={'Provider1'}>} service_date - entry_date)


            If you are looking to group the average by Service and Provider, then you'd need to use Aggr()

            Avg(Aggr(Avg(service_date - entry_date),ServiceName,EntryProvider))