Start here
Lessons and reference
Look things up
Start here
SQL
Power Query
Data modeling
Power BI and DAX
Finance playbooks
Run queries
Build and check
Pick a business question, map its columns to your model, and get the DAX measure, an equivalent T-SQL query and a Power Query step.
The defaults follow the Contoso-style model. Type your own table and column names. Use the form table[column], or 'table name'[column] when the name has a space.
Total sales, growth, margin, days to pay, stock on hand, budget against actual.
Type your own table and column names. The code updates as you type.
Take the DAX, the matching T-SQL check or the Power Query step.
Most finance questions come back to a handful of calculations: total sales, growth against last year, year to date totals, margins, how long customers take to pay, how much stock is on hand, and how actual results compare with budget. Each one is easy to describe in words and easy to get wrong in a formula. This tool gives you a tested pattern for each question, in the three languages you are most likely to use.
Pick a question, then type your table and column names into the boxes. The DAX tab shows the measure for Power BI or Power Pivot. The T-SQL tab shows a query that returns the same answer by month, so you can check the logic against your database. The Power Query M tab shows a step for the questions that fit a query, such as a column or a grouped table.
Time questions need a complete date table with one row for each day, marked as the date table in your model. Year to date, quarter to date, the rolling twelve months and the same period last year all depend on it. The SQL uses a month list from the same date table, so months with no sales still count as zero and the window functions see every month in order.
Ratios use DIVIDE in DAX and NULLIF in SQL, so a zero denominator gives a blank, not an error. Totals are added before they are divided. An average of row percentages is not the same as a percentage of totals, so every ratio here divides totals.
Each recipe has three short notes. "When to use it" says what question the measure answers. "Watch out for" lists the traps: filters, blanks, timing and definitions that differ between companies.
Check the result against a figure you already trust, such as a total from your ledger or a report from your system. Measures depend on how your data is loaded, so a result that looks right for one month should be tested for another. The SQL uses the sample column names you typed, so a query that fails usually has a name that does not match your table.
DIVIDE returns a blank when the denominator is zero or blank. A slash returns an error that breaks the visual, and wrapping the formula in IFERROR hides real problems. DIVIDE is the usual choice for ratios in Power BI.
Most time measures need a monthly series to run totals and comparisons. Each row is one month, and the window functions work across those rows in order. Shares of the total and the rank are not monthly, so those queries return one row per total or per customer.
Yes. Enter the month and day in the fiscal year end box, such as 6/30 for a June year end. The DAX uses DATESYTD with that date, and the SQL restarts its running total at the same month.
The DAX tab lists every DAX function used in the measure. Each name links to its function page when that page exists in the function reference.
No. The generator runs in your browser. It checks the names you type for the right format, builds text, and stores nothing. Copy the code into your own model or query.
More tools: all tools · function reference · guides