malloy-gotchas-queries

Documents common Malloy query and view mistakes with corrected syntax patterns.

Updated Jun 3, 2026
One-click install
npx skills add https://github.com/credibledata/credible-plugin --skill malloy-gotchas-queries-credibledata
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: malloy-gotchas-queries
Source: https://github.com/credibledata/credible-plugin/tree/main/codex/skills/malloy-gotchas-queries
Command: npx skills add https://github.com/credibledata/credible-plugin --skill malloy-gotchas-queries-credibledata

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Malloy views and queries often fails on recurring compile errors—aggregate filters in the wrong clause, unaliased joined fields in order_by, method syntax misuse, and chart annotation placement—that are hard to diagnose from cryptic compiler messages. ## Core Features & Use Cases - Compile Error Prevention: Catalogs the most frequent Malloy mistakes (having vs where, dotted join paths, order_by output columns) with wrong/right code pairs. - Syntax Rule Reference: Clarifies method syntax for aggregates over joined paths, scalar function call forms, clause separators, and the ? alternation operator. - Chart & Time Guidance: Explains the one-aggregate-per-chart constraint, annotation placement on nested views, and time truncation vs extraction semantics. - Use Case: Before writing a Malloy view that groups by a joined field and filters on an aggregate, consult this reference to alias the joined field, use having: instead of where:, and avoid a compile failure. ## Quick Start Review the Malloy gotchas before writing any view, query, or notebook so the query compiles on the first attempt.

Frequently Asked Questions about malloy-gotchas-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I filter on an aggregate in a Malloy query?

Use the `having:` clause to filter on aggregates after aggregation, and reserve `where:` for filtering rows before aggregation on dimensions or raw columns. Writing `where: n > 10` on a measure produces an "Aggregate expressions not allowed in where" compile error.

Why does order_by fail on a joined field in Malloy?

Malloy's `order_by:` resolves only against the query's output columns, not source fields. When grouping by a joined field, first alias it in `group_by:` (e.g., `group_by: yr is races.season_year`) and then reference the alias in `order_by: yr`.

When should I use method syntax like field.sum() in Malloy?

Method syntax is required for aggregates over a joined path, such as `inventory_items.item_cost.sum()`; the plain `sum(joined.field)` form fails to compile. Scalar functions like `round`, `floor`, and `ceil` never use method syntax and must be called as `round(x, 2)`.

What is the difference between ts.month and month(ts) in Malloy?

`ts.month` truncates a timestamp to the start of the month and returns a timestamp, which is correct for time series charts. `month(ts)` extracts the month as an integer from 1 to 12, which suits cross-year comparisons.

Why does my Malloy chart view ignore one of my measures?

Charts render only the first aggregate in a view, so a `# bar_chart` or `# line_chart` view must contain exactly one aggregate. For multiple metrics, nest separate chart views inside a `# dashboard` or use `y=['revenue','cost']` for multi-measure series.