Model
Modeling best practices
Rules for modeling data so that it groups, formats and compares the way people expect, each from a real case.
Each rule on this page comes from a real case. The rules come first, grouped by what you model. The cases follow, each with what we saw, the problem it caused and the practice that prevents it. We add a case each time a model surprises someone. Your agent reads the same page in Kater, as vfs://guides/modeling-practices.md.
Rules
Dates and times
- Keep a date at the type its values have. A
DATEcolumn stays aDATE. Do not cast it to a timestamp and back, asTO_DATE(TO_TIMESTAMP(date_day))does. It changes nothing, and it makes a reader think the source held text. See Case 1. - Never store a date as formatted text, such as
Jul 2025or2025-07. Keep the date, group it with a grain such asKATER__MONTH, and show it with a format. Text sorts as text, cannot be compared by period and cannot change grain. - Parse a text date one time, with its exact format. When a source holds a date as text, parse it in the Kater dataset, such as
TRY_TO_DATE(month_label, 'MON YYYY'), then group the parsed date. Do not cast text to a timestamp and hope the warehouse reads it. - Keep the finest grain the source has. A query can group days by month. It cannot get the days back from a month.
- A grain follows the field. A column that a query groups by month is a month in every query that reads it, through a plain column, a cast,
MINandMAX. So a query that reads a monthly query shows Month with noKATER__MONTHof its own. To see days or weeks, read the source field, not the monthly query. Dates and times has each grain. - Union branches at one grain. A
UNION ALLof a monthly branch and a daily branch holds days, so its column shows as a raw date, not Month. Group every branch to the same grain, or group the union after it, such asKATER__MONTH(u.date_day)over the union. - Name a column of periods for its period. Declare it with its grain, such as
DIMENSION('date_month', KATER__MONTH(src.date_day)), and label it “Reporting Month”. The field then carries its grain, and nobody groups it finer by mistake.
Codes and names
- Map a code to its name one time, in the shared model. Declare the name as its own field beside the code. A query that writes its own
CASEfor the names spells them differently, and two charts then show two names for one thing. See Case 2. - Say which field to use for what. The code’s description and the name’s description each point to the other.
Amounts and units
- Keep an amount’s unit beside it. Keep the currency as a field, and format the amount by it:
-- @format currency(union__currency, 2). See Case 3. - Declare that an amount adds up only within one unit. Write
NOT_ADDITIVE_ACROSS(unit)on the measure, and group or filter by the unit in each query that totals it.
Cases
Case 1: Reporting Date looks like text and shows Month
What we saw. A Paid Media Review query, Monthly paid media spend, showed Reporting Date as Jul 2025, Aug 2025 and so on, and the field picker marked a grain under Reporting Date. The shared Ad Reporting model declares the field over TO_DATE(TO_TIMESTAMP(date_day)). It looked as if the source held month names as text, the model cast them to a timestamp, and the result was called Month with no DATE_TRUNC and no KATER__ function.
The problem. The source column is a DATE, one row for each day. The cast to a timestamp and back to a date changes no value, but it reads like a parse of text. The month came from the query itself: it selects KATER__MONTH(ad_reporting.union__date_day), which keeps the field’s name and label, and a month shows as Jul 2025. A query that reads this monthly query, and selects the plain column, still shows Month. Its values are the first days of months, so the grain follows the data, not the function in the query’s own text.
The practice.
- Keep the date at its own type in the model:
base.date_day, with no round trip through a timestamp. - Group in the query with
KATER__MONTH, and let the month format show it. Never make a text column such asJul 2025in the model. - When a field holds periods, name and label it for the period, such as
date_monthand “Reporting Month”. - To check a field’s grain, read its source column’s type in the database dataset, then the first function around it in the query that shows it.
Since then. The Ad Reporting models of Kater’s starter content read date_day as the DATE it is, with no round trip through a timestamp.
Case 2: A query spelled the platform names its own way
What we saw. The shared Ad Reporting model has Platform, the codes facebook_ads, google_ads and tiktok_ads, and Ad Platform, the names Google Ads, Meta Ads and TikTok Ads. A query grouped by Platform and wrote its own CASE to turn the codes into names.
The problem. The query’s names were Meta ads and TikTok ads, and the model’s are Meta Ads and TikTok Ads. A chart of the query and a chart that reads Ad Platform show two names for one platform, and a filter on one name does not match the other.
The practice.
- Map codes to names one time, in the shared model, and group by that field, not by a
CASEof your own. - Let each field’s description say which one to use, as Platform’s does: “To show or group by the platform’s name, use Ad Platform.”
Case 3: Spend in many currencies adds up to one figure
What we saw. The shared Ad Reporting model holds each account’s spend in the account’s own currency, with Currency beside it.
The problem. A total of Spend over all accounts adds US dollars to other currencies, which gives a figure in no currency.
The practice.
- Keep Currency as a field, and format Spend by it:
-- @format currency(union__currency, 2). - Declare the rule on the measure:
MEASURE('sum__spend', SUM(base.spend), NOT_ADDITIVE_ACROSS(union__currency)) AS "Spend". A query that adds Spend across Currency then gets the warningnot_additive_across, with a fix that groups by it. - Group each total of spend by Currency, or filter it to one currency.