MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

Power-Bi-Dax-Best-Practices

Power-Bi-Dax-Best-Practices是一款code方向的AI技能,核心价值是Comprehensive Power BI DAX best practices and patterns based on Microsoft guidance for creating efficient, maintainable, and performant DAX formulas,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

Comprehensive Power BI DAX best practices and patterns based on Microsoft guidance for creating efficient, maintainable, and performant DAX formulas.

Last verified on: 2026-05-30
mkdir -p ./skills/power-bi-dax-best-practices && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/power-bi-dax-best-practices/SKILL.md -o ./skills/power-bi-dax-best-practices/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Power BI DAX Best Practices


Overview

This document provides comprehensive instructions for writing efficient, maintainable, and performant DAX (Data Analysis Expressions) formulas in Power BI, based on Microsoft's official guidance and best practices.


Core DAX Principles


1. Formula Structure and Variables

Always use variables to improve performance, readability, and debugging:


dax
// ✅ PREFERRED: Using variables for clarity and performance
Sales YoY Growth % =
VAR CurrentSales = [Total Sales]
VAR PreviousYearSales = 
    CALCULATE(
        [Total Sales],
        SAMEPERIODLASTYEAR('Date'[Date])
    )
RETURN
    DIVIDE(CurrentSales - PreviousYearSales, PreviousYearSales)

// ❌ AVOID: Repeated calculations without variables  
Sales YoY Growth % =
DIVIDE(
    [Total Sales] - CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date])),
    CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))
)

**Key Benefits of Variables:**

- **Performance**: Calculations are evaluated once and cached

- **Readability**: Complex formulas become self-documenting

- **Debugging**: Can temporarily return variable values for testing

- **Maintainability**: Changes need to be made in only one place


2. Proper Reference Syntax

Follow Microsoft's recommended patterns for column and measure references:


dax
// ✅ ALWAYS fully qualify column references
Customer Count = 
DISTINCTCOUNT(Sales[CustomerID])

Profit Margin = 
DIVIDE(
    SUM(Sales[Profit]),
    SUM(Sales[Revenue])
)

// ✅ NEVER fully qualify measure references
YTD Sales Growth = 
DIVIDE([YTD Sales] - [YTD Sales PY], [YTD Sales PY])

// ❌ AVOID: Unqualified column references
Customer Count = DISTINCTCOUNT([CustomerID])  // Ambiguous

// ❌ AVOID: Fully qualified measure references
Growth Rate = DIVIDE(Sales[Total Sales] - Sales[Total Sales PY], Sales[Total Sales PY])  // Breaks if measure moves

3. Error Handling Strategies

Implement robust error handling using appropriate patterns:


dax
// ✅ PREFERRED: Use DIVIDE function for safe division
Profit Margin = 
DIVIDE([Total Profit], [Total Revenue])

// ✅ PREFERRED: Use defensive strategies in model design
Average Order Value = 
VAR TotalOrders = COUNTROWS(Orders)
VAR TotalRevenue = SUM(Orders[Amount])
RETURN
    IF(TotalOrders > 0, DIVIDE(TotalRevenue, TotalOrders))

// ❌ AVOID: ISERROR and IFERROR functions (performance impact)
Profit Margin = 
IFERROR([Total Profit] / [Total Revenue], BLANK())

// ❌ AVOID: Complex error handling that could be prevented
Unsafe Calculation = 
IF(
    OR(
        ISBLANK([Revenue]),
        [Revenue] = 0
    ),
    BLANK(),
    [Profit] / [Revenue]
)

DAX Function Categories and Best Practices


Aggregation Functions

dax
// Use appropriate aggregation functions for performance
Customer Count = DISTINCTCOUNT(Sales[CustomerID])  // ✅ For unique counts
Order Count = COUNTROWS(Orders)                    // ✅ For row counts  
Average Deal Size = AVERAGE(Sales[DealValue])      // ✅ For averages

// Avoid COUNT when COUNTROWS is more appropriate
// ❌ COUNT(Sales[OrderID]) - slower for counting rows
// ✅ COUNTROWS(Sales) - faster and more explicit

Filter and Context Functions

dax
// Efficient use of CALCULATE with multiple filters
High Value Customers = 
CALCULATE(
    DISTINCTCOUNT(Sales[CustomerID]),
    Sales[OrderValue] > 1000,
    Sales[OrderDate] >= DATE(2024,1,1)
)

// Proper context modification patterns
Same Period Last Year = 
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR('Date'[Date])
)

// Using FILTER appropriately (avoid as filter argument)
// ✅ PREFERRED: Direct filter expression
High Value Orders = 
CALCULATE(
    [Total Sales],
    Sales[OrderValue] > 1000
)

// ❌ AVOID: FILTER as filter argument (unless table manipulation needed)
High Value Orders = 
CALCULATE(
    [Total Sales],
    FILTER(Sales, Sales[OrderValue] > 1000)
)

Time Intelligence Patterns

dax
// Standard time intelligence measures
YTD Sales = 
CALCULATE(
    

🎯 Best For

  • UI designers
  • Product designers
  • Claude users
  • GitHub Copilot users
  • Software engineers

💡 Use Cases

  • Generating component mockups
  • Creating design system tokens
  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Power-Bi-Dax-Best-Practices to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Does this work with Figma?

Some design skills integrate with Figma plugins. Check the Works With section for supported tools.

Is Power-Bi-Dax-Best-Practices compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Power-Bi-Dax-Best-Practices?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Power-Bi-Dax-Best-Practices?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/power-bi-dax-best-practices/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping usability testing

AI-generated designs should be validated with real users before development.

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills