As a large segment Marketing Cloud Engagement customer, you may find the need to split your audiences up. In some scenarios it may be necessary to deliberately split audiences up for performance optimization in downstream processes or conversely just producing an audience sample. Querying using the modulo operator on _CustomObjectKey in Salesforce Marketing Cloud is a technique that is particularly well suited for both of these purposes.
Improved Performance: Breaking down large queries into smaller, more manageable chunks can prevent timeouts and improve the efficiency of SQL queries, especially in automations.
Targeted Processing: You can process specific segments of your data independently, which is useful for A/B testing, phased rollouts, or addressing specific data issues.
Workload Management: Distributing the workload across multiple queries or activities can help manage server load and resource consumption.
_CustomObjectKey: This is a hidden, automatically assigned, and incrementing numerical identifier for each row in a Data Extension.
Modulo Operator (%): The modulo operator returns the remainder of a division. For example, _CustomObjectKey % 4 would return 0, 1, 2, or 3.
Segmentation: By using _CustomObjectKey % N = X, where N is the number of desired segments and X is a specific remainder (from 0 to N-1), you can divide your data into approximately equal-sized groups.
Approximate Distribution: While _CustomObjectKey is sequential, its distribution might not always be perfectly even across all segments, especially if records are frequently added or deleted.
Data Extension Type: This method is most effective with standard data extensions where _CustomObjectKey is consistently assigned.
Alternative Segmentation: For precise, mathematically balanced segmentation, consider using techniques like NTILE() or custom ranking logic if the slight unevenness of modulo-based segmentation is unacceptable.
The only requisite of creating and applying this will be the creation of each individual target Data Extension. After these have been created, there are no other pre-requisites to applying this more performant segmentation method.
SELECT *FROM YourDataExtensionWHERE _CustomObjectKey % 4 = 0;
SELECT *FROM YourDataExtensionWHERE _CustomObjectKey % 4 = 1;
SELECT *FROM YourDataExtensionWHERE _CustomObjectKey % 4 = 2;
SELECT *FROM YourDataExtensionWHERE _CustomObjectKey % 4 = 3;
005224376

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.