The Datarails Excel Add-In: Average and Count Unique with DR.INCLUDE

This article explains how the average and count unique functions behave inside DR.GET, and how their results can differ when combined with DR.INCLUDE.

Function Overview

DR.GET Function

The `DR.GET` function is a special function in our Excel add-in designed to perform operations on data fields from a database. The function allows filtering based on specific parameters and can include multiple parameters for a single field using the `DR.include` feature.

Syntax

=DR.GET(Value, "[Field1]", "Value1", "[Field2]", "Value2", ..., "[FieldN]", DR.Include("Param1", "Param2", ...))
Value: The function operation (e.g., average, count unique) to perform on a specific field (e.g., "Amount").
[FieldX]: Database fields to filter the query.
ValueX: Values within the database fields to filter by.
DR.Include: Allows multiple parameters for a single field in the query.

Example Formula

=DR.GET(Value,"[Reporting Month]","12/31/24","[Scenario]","Actuals","[Animal Group]",DR.Include ("Cats","Dogs","Birds"))

In this example:
Value: Represents the function to perform, such as average.
[Reporting Month]: Field in the database to filter by "12/31/24".
[Scenario]: Field in the database to filter by "Actuals".
[Animal Group]: Field in the database to filter by "Cats", "Dogs", and "Birds" using `DR.Include`.

The examples below all use this shape, where Value is the operation being tested, either average or count unique.

Average

Standard average

The average function returns the mean of the values in the set.

  • Data: [2, 4, 6, 8, 10, 12, 14]
  • Calculation: (2 + 4 + 6 + 8 + 10 + 12 + 14) / 7 = 8

Average with DR.INCLUDE

With DR.INCLUDE, the server calculates the average for each group, then averages those group averages.

=DR.GET("average","[Reporting Month]","12/31/24","[Scenario]","Actuals","[Animal Group]", DR.INCLUDE("Cats","Dogs","Birds"))
Animal GroupAmount
Cats2
Cats4
Dogs6
Dogs8
Birds10
Birds12
Birds14

Grouped by Animal Group:

  • Cats: (2 + 4) / 2 = 3
  • Dogs: (6 + 8) / 2 = 7
  • Birds: (10 + 12 + 14) / 3 = 12
  • Result: (3 + 7 + 12) / 3 = 7.33

Compare:

 Result
Without DR.INCLUDEAverage of all seven rows = 8
With DR.INCLUDEAverage of the group averages = 7.33

This is a case where the average of averages is not equal to the overall average.

Count unique

Standard count unique

The count unique function returns how many distinct values are in the set.

  • Data: [2, 4, 6, 6]
  • Unique values: [2, 4, 6]
  • Result: 3

Count unique with DR.INCLUDE

With DR.INCLUDE, the server counts unique values within each group, then sums those counts.

=DR.GET("count unique","[Reporting Month]","12/31/24","[Scenario]","Actuals","[Animal Group]", DR.INCLUDE("Cats","Dogs","Birds"))

Example 1: the results match

Animal GroupAmount
Cats2
Cats4
Cats4
Dogs6
Dogs8
Dogs8
Birds10
Birds12
Birds12
  • Cats: 2 unique, [2, 4]
  • Dogs: 2 unique, [6, 8]
  • Birds: 2 unique, [10, 12]
  • Result: 2 + 2 + 2 = 6
 Result
Without DR.INCLUDE6 unique across all rows, [2, 4, 6, 8, 10, 12]
With DR.INCLUDESum of group counts = 6


Example 2: the results differ

Animal GroupAmount
Cats2
Cats4
Cats6
Dogs4
Dogs8
Dogs10
Birds6
Birds10
Birds12
  • Cats: 3 unique, [2, 4, 6]
  • Dogs: 3 unique, [4, 8, 10]
  • Birds: 3 unique, [6, 10, 12]
  • Result: 3 + 3 + 3 = 9
 Result
Without DR.INCLUDE6 unique across all rows, [2, 4, 6, 8, 10, 12]
With DR.INCLUDESum of group counts = 9

This is a case where the sum of the group counts differs from the overall count unique, because the same value appears in more than one group and is counted once per group.

 




© Datarails Ltd. All rights reserved.

Updated

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.