How to Use AI to Write DAX Measures: 5 Powerful Prompts for Power BI

Writing DAX can sometimes feel less like writing a formula and more like solving a puzzle.

You know what you want to calculate:

“I need to compare this month’s sales with last month.”

Or:

“I want the average sales from the beginning of the year up to the selected month.”

But translating that business requirement into the correct DAX measure requires an understanding of filter context, relationships, date tables, CALCULATE, time intelligence, and the structure of your data model.

This is where AI tools such as ChatGPT and Claude can become useful assistants for Power BI developers and data analysts.

The important word here is assistants.

AI should not replace your understanding of DAX. Instead, you can use it to help translate your analytical requirement into DAX, explain existing measures, troubleshoot errors, suggest alternatives, and improve your formulas.

The quality of the answer, however, depends heavily on the quality of the prompt.

In this guide, we will look at five practical prompts you can use with AI to write better DAX measures, along with examples of how to provide the context AI needs.

Why Use AI for DAX?

DAX is powerful, but it can also be difficult to write and debug.

An analyst may understand the business requirement perfectly but struggle with the exact DAX syntax.

For example, suppose you want to calculate:

Current Month Sales − Previous Month Sales

The business logic is simple.

The DAX implementation might require:

  • A proper date table
  • A relationship between the date table and fact table
  • A base sales measure
  • Appropriate filter context
  • Time-intelligence logic

AI can help bridge the gap between the business requirement and the DAX implementation.

You can ask AI to:

  • Write a DAX measure
  • Explain a DAX measure
  • Debug DAX
  • Optimize DAX
  • Convert business logic into DAX
  • Suggest alternative approaches
  • Explain why a calculation returns an unexpected result

But there is one major rule:

Don’t simply ask AI: “Write DAX for me.”

Give it context.

The Most Important Rule: Give AI Your Data Model Context

Consider these two prompts.

Weak prompt

Write a DAX measure for monthly sales growth.

The AI doesn’t know:

  • Your table name
  • Your sales column
  • Your date table
  • Your date column
  • Whether you already have a sales measure
  • Whether your visual is using Year/Month
  • What type of comparison you actually need

The result may look correct but fail in your Power BI model.

Better prompt

I have a Power BI model with a Sales table containing Sales[SalesAmount] and Sales[OrderDate]. I also have a Calendar table called Calendar with Calendar[Date], related to Sales[OrderDate].

I already have this measure:

Total Sales = SUM(Sales[SalesAmount])

I need a measure that calculates the difference between the current month and the previous month. The visual uses Calendar[Year] and Calendar[Month]. Please write the DAX measure and explain how it works.

Now AI has enough information to reason about the calculation.

This is the difference between asking AI to guess and asking AI to work with your model.

Prompt 1: Ask AI to Write a DAX Measure From a Business Requirement

This is probably the most common use case.

Instead of trying to describe the DAX syntax yourself, describe what you want to calculate in business terms.

Example

Suppose you have:

  • Sales table
  • Sales[SalesAmount]
  • Calendar table
  • Calendar[Date]

You already have:

Total Sales =
SUM(Sales[SalesAmount])

You want to calculate the previous month’s sales.

You can ask ChatGPT or Claude:

Prompt

I am working in Power BI and need help creating a DAX measure.

My model contains:

  • Sales table
  • Sales[SalesAmount]
  • Sales[OrderDate]
  • Calendar table
  • Calendar[Date]

Calendar[Date] has an active relationship with Sales[OrderDate].

I already have this measure:

Total Sales =
SUM(Sales[SalesAmount])

I need a measure that returns the sales for the previous month based on the current filter context.

Please:

  1. Write the DAX measure.
  2. Explain each important part.
  3. Explain what happens when the measure is used in a monthly visual.
  4. Mention any assumptions about the Calendar table.

This is a much better way to use AI.

You’re not just asking for code.

You’re giving AI the business requirement + model structure + existing measure + expected behavior.

Prompt 2: Ask AI to Write DAX Based on Your Exact Data Model

Sometimes the biggest problem is that AI doesn’t know your tables and relationships.

You can solve this by giving it your model structure.

For example:

Sales
- OrderDate
- CustomerID
- ProductID
- Quantity
- SalesAmount
- Cost

Customers
- CustomerID
- CustomerName
- Region

Products
- ProductID
- ProductName
- Category

Calendar
- Date
- Year
- Month
- MonthNumber

Then tell AI what you need.

Prompt

Act as an experienced Power BI and DAX developer.

Here is my data model:

Sales:

  • Sales[OrderDate]
  • Sales[CustomerID]
  • Sales[ProductID]
  • Sales[Quantity]
  • Sales[SalesAmount]
  • Sales[Cost]

Customers:

  • Customers[CustomerID]
  • Customers[CustomerName]
  • Customers[Region]

Products:

  • Products[ProductID]
  • Products[ProductName]
  • Products[Category]

Calendar:

  • Calendar[Date]
  • Calendar[Year]
  • Calendar[Month]
  • Calendar[MonthNumber]

Relationships:

  • Calendar[Date] → Sales[OrderDate]
  • Customers[CustomerID] → Sales[CustomerID]
  • Products[ProductID] → Sales[ProductID]

I need a DAX measure for gross profit margin:

Gross Profit Margin = (Sales – Cost) / Sales

Please create the measure using appropriate DAX best practices. Explain the calculation and tell me whether you recommend separate base measures for Sales, Cost, and Gross Profit.

This approach is especially useful when your model contains multiple fact and dimension tables.

Prompt 3: Ask AI to Debug Your Existing DAX

You don’t always need AI to create a new measure.

One of the most useful applications is debugging.

Suppose you wrote:

Sales LY =
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR(Sales[OrderDate])
)

But the result is incorrect.

Instead of simply asking:

Why doesn’t this work?

Give AI the full context.

Prompt

I am troubleshooting a DAX measure in Power BI.

My measure is:

Sales LY =
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR(Sales[OrderDate])
)

My model contains a Calendar table with Calendar[Date], which has an active relationship to Sales[OrderDate].

My report visual uses Calendar[Year] and Calendar[Month].

The previous-year values are not returning as expected.

Please:

  1. Identify the problem.
  2. Explain why the current measure may fail.
  3. Provide the corrected DAX.
  4. Explain why the corrected version works.
  5. Tell me whether my Calendar table needs to be marked as a date table.

This prompt is much more useful because you’re asking AI to diagnose the problem, not just generate another formula.

Prompt 4: Ask AI to Optimize Your DAX

Sometimes your DAX works, but it isn’t necessarily the best way to write it.

This is where AI can act like a second pair of eyes.

For example:

Customer Sales =
CALCULATE(
    SUM(Sales[SalesAmount]),
    FILTER(
        Sales,
        Sales[CustomerID] = SELECTEDVALUE(Customers[CustomerID])
    )
)

You can ask AI to review it.

Prompt

Act as a senior Power BI performance and DAX expert.

Review the following measure:

[PASTE YOUR DAX HERE]

My model contains approximately 5 million rows in the Sales table.

Please:

  1. Explain what the current measure does.
  2. Identify any unnecessary FILTER operations.
  3. Suggest a more efficient version if possible.
  4. Explain the difference between the original and optimized versions.
  5. Consider filter context, storage engine performance, and readability.
  6. Do not change the business logic.

This last instruction is particularly important.

You don’t want AI to “optimize” your formula by accidentally changing the calculation.

Always tell it:

Do not change the business logic.

Prompt 5: Ask AI to Build a Complex DAX Measure Step by Step

This is where AI can become particularly useful.

Instead of asking for a complicated measure in one sentence, ask AI to break the problem into smaller calculations.

For example, suppose you want:

Year-to-Date Sales → Previous Year YTD → Difference → Percentage Difference

Rather than asking AI for one giant formula, ask it to build the calculation in stages.

Prompt

I need to create a Power BI sales performance calculation.

I want to show:

  1. Current Year-to-Date Sales
  2. Previous Year-to-Date Sales
  3. Difference between current YTD and previous YTD
  4. Percentage change

My model contains:

Sales[SalesAmount]

Calendar[Date]

Calendar[Year]

Calendar[Month]

Calendar[MonthNumber]

Calendar[Date] has an active relationship with Sales[OrderDate].

Please solve this step by step.

First create the base Total Sales measure.

Then create YTD Sales.

Then create Previous Year YTD.

Then create the difference.

Finally create the percentage change.

Explain the purpose of each measure and show the final DAX.

Do not combine everything into one measure unless there is a good reason.

This approach makes complex DAX much easier to understand.

Don’t Just Copy and Paste AI-Generated DAX

This is probably the most important lesson.

AI can generate a DAX measure that looks completely correct and still produce the wrong result in your model.

Why?

Because DAX depends heavily on context.

A measure can be affected by:

  • Filter context
  • Row context
  • Relationships
  • Cross-filter direction
  • Date tables
  • Visual filters
  • Slicers
  • CALCULATE
  • Context transition
  • Data granularity

For example, this:

Total Sales =
SUM(Sales[SalesAmount])

is simple.

But when you introduce:

CALCULATE()

and time intelligence, the evaluation context becomes much more important.

This is why you should ask AI to explain the DAX, not just provide it.

A Better AI + DAX Workflow

A practical workflow for analysts can look like this:

Step 1 — Define the business requirement

Don’t start with DAX.

Start with:

What am I trying to calculate?

For example:

I need to compare current month sales with previous month sales.

Step 2 — Provide the model structure

Tell AI:

  • Fact table
  • Dimension tables
  • Relevant columns
  • Relationships
  • Date table

Step 3 — Provide existing measures

If you already have:

Total Sales =
SUM(Sales[SalesAmount])

give it to AI.

Don’t ask AI to recreate something you already have.

Step 4 — Explain the expected result

Give an example.

For example:

MonthSalesExpected Previous Month
January10,000Blank
February12,00010,000
March15,00012,000

This gives AI a way to understand the expected behavior.

Step 5 — Ask for DAX

Now ask AI to create the measure.

Step 6 — Ask AI to explain it

Ask:

Explain this measure line by line and explain the filter context.

Step 7 — Test it in Power BI

This step cannot be skipped.

Put the measure into a visual and test it against known values.

Step 8 — Return the result to AI if necessary

If the result is wrong, tell AI exactly what happened.

For example:

The measure works for January and February but returns blank for March. Here is my visual and model structure…

Then ask it to diagnose the problem.

Give AI Examples of Expected Results

One of the most powerful techniques is providing expected results.

Suppose your requirement is a cumulative average.

You could tell AI:

My monthly values are:

January = 10
February = 20
March = 20

I expect:

January = 10
February = 15
March = 16.67

Create a DAX measure that produces this cumulative average.

Now AI has something concrete to validate against.

This is much better than saying:

Create a cumulative average.

The more clearly you define the expected behavior, the less AI has to guess.

Use AI to Learn DAX, Not Just Generate DAX

There is another major advantage to using AI.

You can use it as a DAX tutor.

For example, after AI gives you:

Previous Month Sales =
CALCULATE(
    [Total Sales],
    DATEADD(
        'Calendar'[Date],
        -1,
        MONTH
    )
)

Don’t simply paste it into Power BI.

Ask:

Explain exactly how CALCULATE changes the filter context in this measure and how DATEADD modifies the date context.

Then ask:

Give me a simple example using January, February and March.

This turns a code-generation exercise into a learning exercise.

Over time, you’ll begin recognizing DAX patterns instead of depending completely on AI.

AI Can Also Compare Different DAX Approaches

Sometimes there is more than one way to solve a problem.

You can ask AI:

Give me three different approaches to calculate previous-month sales in DAX. Compare them based on readability, performance, compatibility with different date selections, and recommended use cases.

This can help you understand why one solution might be preferable to another.

For example, AI might compare approaches involving:

  • DATEADD
  • PREVIOUSMONTH
  • CALCULATE with explicit date filters

The important thing is not simply getting three formulas.

The important part is understanding when each approach makes sense.

Use AI With Your Power BI Projects

AI becomes even more useful when you provide enough project context.

For example, imagine you’re building a financial dashboard.

You could tell AI:

I am building a financial dashboard in Power BI.

My income statement contains:

Revenue
Cost of Sales
Gross Profit
Operating Expenses
EBITDA
Depreciation
Tax
Net Profit

I need a measure that calculates Gross Margin %.

Revenue is stored in [Revenue].

Cost of Sales is stored in [Cost of Sales].

Gross Profit should be Revenue minus Cost of Sales.

Create the measures using a reusable measure structure rather than repeating SUM calculations.

Now AI has the business context as well as the technical context.

That generally produces a much better result.

Five Prompt Templates You Can Save

If you work with DAX regularly, save these five templates.

1. Generate

Act as a senior Power BI/DAX developer. Here is my data model: [MODEL]. Here are my existing measures: [MEASURES]. I need to calculate: [BUSINESS REQUIREMENT]. Expected result: [EXAMPLE]. Write the DAX and explain how it works.

2. Debug

Here is my DAX: [DAX]. Here is my model: [MODEL]. The result I am getting is [RESULT], but I expect [EXPECTED RESULT]. Identify the problem, explain the filter context, and provide corrected DAX without changing the business logic.

3. Optimize

Review this DAX measure as a senior Power BI performance expert: [DAX]. Explain what it does, identify potential performance or readability issues, and provide an optimized version without changing the business logic.

4. Explain

Explain this DAX measure to me step by step: [DAX]. Explain CALCULATE, filter context, row context, relationships, and any other important concepts involved. Use a small numerical example.

5. Build Complex Logic

Break this business requirement into multiple DAX measures instead of creating one complicated formula: [REQUIREMENT]. First create the base measure, then the intermediate calculations, then the final measure. Explain each step and show the expected result.

What AI Still Cannot Replace

AI is becoming extremely useful for DAX development, but it doesn’t eliminate the need to understand Power BI.

You still need to understand:

Data Modeling

Relationships

Filter Context

DAX

Visualization

Business Logic

If your model is wrong, AI cannot magically fix the entire analytical architecture.

If your business requirement is unclear, AI may produce technically valid DAX that calculates the wrong thing.

And if you don’t understand what the measure is doing, you may not notice when the result is incorrect.

That’s why the best approach is:

Human defines the problem → AI helps develop the solution → Power BI validates the result → Human interprets the insight.

Final Thoughts

AI tools such as ChatGPT and Claude can significantly change how Power BI analysts work with DAX.

The biggest advantage isn’t simply that AI can write a DAX formula.

The real advantage is that AI can help you move faster through the entire DAX development process:

Requirement → DAX → Explanation → Debugging → Optimization → Validation

But the quality of the output depends heavily on the quality of the input.

Instead of asking:

“Write a DAX measure for me.”

Give AI your:

  • Data model
  • Table names
  • Column names
  • Relationships
  • Existing measures
  • Business requirement
  • Expected result
  • Known problems

Then ask AI to explain its reasoning and test the result in Power BI.

That is how you move from using AI to generate DAX to using AI as a DAX development assistant.

And that distinction matters.

Power BI analysts who learn to combine their understanding of data modeling and DAX with AI-assisted development can spend less time fighting syntax and more time focusing on what matters most:

turning data into useful business insights.


Frequently Asked Questions

Can ChatGPT write DAX measures?

Yes. ChatGPT can generate DAX measures from a business requirement, but you should provide your table structure, column names, relationships, existing measures, and expected results whenever possible.

Can Claude write DAX?

Yes. Claude can also help generate, explain, debug, and improve DAX. The same prompting principles apply: provide sufficient context rather than asking for a formula without explaining your model.

Is AI-generated DAX always correct?

No. AI-generated DAX should always be tested in your actual Power BI model. A formula can be syntactically valid but produce incorrect results because of differences in filter context, relationships, granularity, or business logic.

What information should I give AI before asking for DAX?

At minimum, provide the relevant table names, column names, relationships, existing measures, business requirement, and an example of the expected result.

Should I use AI instead of learning DAX?

No. AI is best used as an assistant rather than a replacement for DAX knowledge. Understanding DAX allows you to evaluate AI-generated formulas, identify errors, and modify calculations when your requirements change.

What is the best way to use ChatGPT for Power BI?

Use it as a development and learning assistant. Ask it to generate DAX, explain measures, debug errors, compare approaches, optimize formulas, and teach you the underlying concepts.