dax-udf-authoringlisted
Install: claude install-skill CSalcedoDataBI/dax-for-agents
# DAX UDF Authoring — the mechanics
## Overview
How to write a **correct** DAX user-defined function.
**Most problems should not be a UDF at all.** Reach for one when the same logic is repeated across
measures with only the column or measure reference changing. Do not reach for one to wrap a single
measure — see the per-row trap under Common mistakes. For window machinery inside a rolling or
trailing UDF, see **`dax-window-functions`**.
> **Before writing one from scratch:** search the **`dax-lib`** skill — an index of the
> [daxlib.org](https://daxlib.org) registry (55 packages, ~1,649 functions). `TimeSeries.MovingAverage`
> (SMA/WMA/EMA over native `WINDOW`) may already solve a rolling-average need. The index tells you
> what exists; the code comes from the registry.
**Per-function reference:** **`dax-reference`** carries the signature and semantics of each built-in.
This skill is about the mechanics of authoring your own, plus the gotchas that bite.
## Syntax — define once, two surfaces
```dax
-- DAX Query View (DEFINE) — for testing
DEFINE
/// Descripción JSDoc (aparece en IntelliSense)
/// @param {ANYREF} qtrCol - columna de trimestre fiscal
/// @returns promedio de 4 trimestres
FUNCTION Contoso.Scorecard.Example = ( qtrCol : ANYREF, metric : ANYREF, N : SCALAR INT64 = 4 ) =>
<body>
```
```tmdl
-- TMDL view — saves to the model
createOrReplace
/// Descripción
function 'Contoso.Scorecard.Example' = ( qtrCol : ANYREF ) => <body>
```