dax
Writes DAX measures, calculated columns, and calculations for Power BI. Use for business logic, time intelligence, and analytical calculations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Writes DAX measures, calculated columns, and calculations for Power BI. Use for business logic, time intelligence, and analytical calculations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Applies Power BI best practices, BPA rules, and enterprise standards. Use for quality validation, naming conventions, and performance optimization.
Creates calculation groups for reusable DAX patterns like time intelligence and currency conversion. Use to replace repetitive measures with dynamic calculations.
Implements CI/CD pipelines and DevOps practices for Power BI. Use for automated validation, testing, and deployment of PBIP projects.
Creates and manages Power BI Desktop Project (PBIP) structure. Use when starting new Power BI projects, setting up folder structure, or configuring project files.
Writes Power Query (M language) for data transformation, connections, and ETL. Use for data sources, transformations, parameters, and query optimization.
Creates Power BI reports and visuals in PBIR format. Use for pages, charts, tables, slicers, and visual configuration.
| name | dax |
| description | Writes DAX measures, calculated columns, and calculations for Power BI. Use for business logic, time intelligence, and analytical calculations. |
This skill helps write DAX measures, calculated columns, and calculations for Power BI semantic models.
Follow SQLBI formatting conventions for readable, maintainable DAX:
Measure Name =
VAR VariableName = Expression
VAR AnotherVariable = AnotherExpression
RETURN
Result
Total Sales =
VAR SalesAmount = SUM(Sales[Amount])
VAR ReturnAmount = SUM(Returns[Amount])
VAR NetSales = SalesAmount - ReturnAmount
RETURN
NetSales
Sales YTD =
CALCULATE(
[Total Sales],
DATESYTD(Date[Date])
)
Filtered Sales =
CALCULATE(
[Total Sales],
FILTER(
ALL(Products),
Products[Category] = "Electronics"
)
)
/// Total of all sales amounts
Total Sales =
SUM(Sales[Sales Amount])
/// Count of distinct customers
Customer Count =
DISTINCTCOUNT(Sales[Customer ID])
/// Average order value
Average Order Value =
AVERAGE(Sales[Order Amount])
/// Maximum sale amount
Max Sale =
MAX(Sales[Sales Amount])
Always use DIVIDE() instead of the / operator:
/// Profit margin percentage
Profit Margin % =
VAR Revenue = SUM(Sales[Revenue])
VAR Profit = SUM(Sales[Profit])
RETURN
DIVIDE(Profit, Revenue, 0)
/// Sales as percentage of total
Sales % of Total =
VAR CurrentSales = [Total Sales]
VAR AllSales = CALCULATE([Total Sales], ALL(Sales))
RETURN
DIVIDE(CurrentSales, AllSales, 0)
/// Running total of sales
Cumulative Sales =
CALCULATE(
[Total Sales],
FILTER(
ALL(Date),
Date[Date] <= MAX(Date[Date])
)
)
/// Year-to-date sales
Sales YTD =
CALCULATE(
[Total Sales],
DATESYTD(Date[Date])
)
/// Month-to-date sales
Sales MTD =
CALCULATE(
[Total Sales],
DATESMTD(Date[Date])
)
/// Quarter-to-date sales
Sales QTD =
CALCULATE(
[Total Sales],
DATESQTD(Date[Date])
)
/// Sales from same period last year
Sales PY =
CALCULATE(
[Total Sales],
SAMEPERIODLASTYEAR(Date[Date])
)
/// Year-over-year growth percentage
Sales YoY % =
VAR CurrentSales = [Total Sales]
VAR PriorYearSales = [Sales PY]
RETURN
DIVIDE(
CurrentSales - PriorYearSales,
PriorYearSales,
BLANK()
)
/// Year-to-date sales from last year
Sales PYTD =
CALCULATE(
[Total Sales],
SAMEPERIODLASTYEAR(Date[Date]),
DATESYTD(Date[Date])
)
/// 3-month moving average
Sales 3M Avg =
AVERAGEX(
DATESINPERIOD(
Date[Date],
MAX(Date[Date]),
-3,
MONTH
),
[Total Sales]
)
/// Sales for Electronics category only
Electronics Sales =
CALCULATE(
[Total Sales],
Products[Category] = "Electronics"
)
/// Sales ignoring all filters
Total Sales All =
CALCULATE(
[Total Sales],
ALL(Sales)
)
/// Sales ignoring product filter only
Sales All Products =
CALCULATE(
[Total Sales],
REMOVEFILTERS(Products)
)
/// Percentage within category
% of Category =
VAR CurrentSales = [Total Sales]
VAR CategorySales =
CALCULATE(
[Total Sales],
ALLEXCEPT(Products, Products[Category])
)
RETURN
DIVIDE(CurrentSales, CategorySales, 0)
/// Extended price (quantity * unit price)
Extended Price =
SUMX(
Sales,
Sales[Quantity] * Sales[Unit Price]
)
/// Average sales per customer
Avg Sales per Customer =
AVERAGEX(
VALUES(Customers[Customer ID]),
[Total Sales]
)
/// Product rank by sales
Product Rank =
RANKX(
ALL(Products[Product Name]),
[Total Sales],
,
DESC,
Dense
)
/// Sales from top 10 products only
Top 10 Products Sales =
CALCULATE(
[Total Sales],
TOPN(
10,
ALL(Products[Product Name]),
[Total Sales],
DESC
)
)
/// Sales summary by category
Category Summary =
SUMMARIZE(
Sales,
Products[Category],
"Total Sales", [Total Sales],
"Avg Price", AVERAGE(Sales[Unit Price])
)
/// Products with calculated fields
Products Extended =
ADDCOLUMNS(
Products,
"Sales Amount", [Total Sales],
"Rank", [Product Rank]
)
/// High-value orders only
High Value Orders =
CALCULATE(
[Order Count],
FILTER(
Sales,
Sales[Amount] > 1000
)
)
Always use variables for:
/// Complex calculation with variables
Profit Analysis =
VAR TotalRevenue = SUM(Sales[Revenue])
VAR TotalCost = SUM(Sales[Cost])
VAR TotalProfit = TotalRevenue - TotalCost
VAR ProfitMargin = DIVIDE(TotalProfit, TotalRevenue, 0)
VAR MarginCategory =
SWITCH(
TRUE(),
ProfitMargin >= 0.3, "High",
ProfitMargin >= 0.1, "Medium",
"Low"
)
RETURN
MarginCategory
/// Safe calculation with fallback
Safe Ratio =
IFERROR(
[Total Sales] / [Total Cost],
0
)
/// Replace blank with zero
Sales or Zero =
COALESCE([Total Sales], 0)
/// Conditional formatting flag
Has Sales =
NOT(ISBLANK([Total Sales]))
Measures in TMDL files:
/// Year-to-date sales calculation
/// Use with Date table marked as date table
measure 'Sales YTD' =
CALCULATE(
[Total Sales],
DATESYTD(Date[Date])
)
formatString: "$#,##0.00"
displayFolder: Time Intelligence
lineageTag: a1b2c3d4-e5f6-7890-abcd-ef1234567890
/ operator/// commentsAfter creating measures:
best-practices skill to check DAX qualityreport-visuals skill to displayMeasures reference each other in a loop. Break the cycle by restructuring.
Check table and column names match exactly (case-sensitive).
Data type mismatch. Ensure compatible types in comparisons.
Filter context removed something needed. Review CALCULATE modifiers.