Skip to main content

Compute Counts

Designer Cloud supports computation of counts of rows, columns, and ad-hoc values within your data, so that you can make assessments of the quality, consistency, and statistical validity of your data.

Important Note on Counts

Warnung

Any computed counts that you see in the Transformer page are computed from the displayed sample.

These computed counts reflect the entire dataset, only if the data grid is displaying the full dataset:

ComputeCounts-FullData.png

Figure: Data grid sample is the full dataset.

When the job is executed, however, any computations of counts are applied across the entire dataset.

Visual Profiling

When you run a job, you can enable the profiling of the job results, which renders a visual profile and some statistics on the dataset. This profile is available for review through the application. For more information, see Overview of Visual Profiling.

Row and Column Counts

In the status bar at the bottom of the data grid, you can review the current count of rows and columns in the displayed sample.

Tipp

The row and column counts in the status bar may be useful for comparing the changes to these metrics between steps. For example, you can click step 2 in your recipe and then review these metrics. When you click step 3, these metrics may change.

Row counts: Depending on your method of sampling, the row counts may change. For more information, see Overview of Sampling.

Column counts: By default, all columns in the panel are displayed. Column counts should change only if you delete or hide them.

Computed row counts

You can use the following functions to identify and compute the row counts in your dataset.

Function Name

Description

COUNT Function

Generates the count of rows in the dataset. Generated value is of Integer type.

Tipp

Typically, this function is used as part of an aggregation, in which rows are grouped according to shared values in other columns. This function can also be applied without grouping, which is called a flat aggregate. More information on how to apply aggregated counts is below.

ROWNUMBER Function

Generates a new column containing the row number as sorted by the order parameter and optionally grouped by the group parameter.

SOURCEROWNUMBER Function

Returns the row number of the current row as it appeared in the original source dataset before any steps had been applied.

Anmerkung

This function may fail to return results if the original source row information is not available. For example, if you have performed a join between multiple datasets, the source row number information cannot be computed. Similarly, if you compute this function and then perform a join, the results may not make sense.

Tipp

You can pair this function later with the MIN or MAX functions to compute the highest and lowest row number information.

Count by Pattern

These transformations allow you to compute counts of literals or patterns in a cell's values. Then, you can perform calculations on this new column of values to compute metrics across the dataset.

Count pattern or text

The following example computes the number of references in the tweet column for My Company:

Transformation Name

Count matches

Parameter: Option

Text or pattern

Parameter: Text or pattern to count

'My Company'

Parameter: New column name

tweetCompanyReferences

Suppose, however, that the company has multiple ways in which it is reference. It could be:

  • My Company

  • My Co

  • My Company, Inc.

You can modify the above transformation to use a Wrangle to capture these variations:

Transformation Name

Count matches

Parameter: Option

Text or pattern

Parameter: Text or pattern to count

`(My Company|My Co|My Company, Inc.)`

Parameter: New column name

tweetCompanyReferences

If needed, you can use the following to add up all of the counts in tweetCompanyReferences to determine the total number.

Anmerkung

Keep in mind that this sum reflects only the sum of values in the sample in the data grid. When you run a job containing this calculation, it is applied across all rows in the dataset.

Transformation Name

New formula

Parameter: Formula type

Single row formula

Parameter: Formula

SUM(tweetCompanyReferences)

Parameter: New column name

sum_tweetCompanyReferences

Count between patterns

You can also collect counts of values between two patterns within a cell's value. In this manner, you can analyze a more constrained substring of the cell value.

The following transformation calculates the URLs in each row of the msgText column, assuming that the URL begins with http:// or https:// and ends with .com or .net:

Transformation Name

Count matches

Parameter: Option

Between two delimiters

Parameter: Starting pattern

`(http\:\/\/|https\:\/\/)`

Parameter: Include as part of the match

Selected

Parameter: Ending pattern

`(\.com|\.net)`

Parameter: Includes as part of the match

Selected

Parameter: Ignore case

Selected

Parameter: New column name

countURLs

Count Functions

Aggregated counts

You can perform calculations based on groups that you define as part of the calculation. These groupings, called aggregations, are powerful tools for delivering insightful analysis on your data.

In the following example, several aggregated computations, including the COUNT function are performed on transactional data, which is grouped by region (regionId) and product (prodId):

Transformation Name

Group by

Parameter: Group by 1

regionId

Parameter: Group by 2

prodId

Parameter: Values 1

SUM(sales)

Parameter: Values 2

COUNT()

Parameter: Type

Group by as new column(s)

Anmerkung

The above calculation inserts two new columns into the dataset. Alternatively, you can choose to do a full replacement of the dataset with these aggregated counts. For more information, see Pivot Data.

Conditional count functions

You can use a set of functions that count occurrences, based on conditions. In the following list of functions:

  • Some of the conditions are implicit in the function itself. For example, COUNTA counts values that are non-null.

  • Some conditions are specified as part of the function. For example, COUNTIF tabulates counts provided a specified condition is met.

Function Name

Description

COUNTIF Function

Generates the count of rows in each group that meet a specific condition. Generated value is of Integer type.

COUNTA Function

Generates the count of non-null rows in a specified column, optionally counted by group. Generated value is of Integer type.

COUNTAIF Function

Generates the count of non-null values for rows in each group that meet a specific condition.

COUNTDISTINCT Function

Generates the count of distinct values in a specified column, optionally counted by group. Generated value is of Integer type.

COUNTDISTINCTIF Function

Generates the count of distinct non-null values for rows in each group that meet a specific condition.

The following transformation counts the rows where the length of msgText is longer than 140 characters, grouped by userId:

Transformation Name

Group by

Parameter: Group by 1

userId

Parameter: Values 1

COUNTIF(LEN(msgText)>140)

Parameter: Type

Group by as new column(s)