How to Create Measures Using DAX Query View in Power BI Desktop (Step-by-Step Guide)

How to Create Measures Using DAX Query View in Power BI Desktop (Step-by-Step Guide)

One of the biggest improvements in recent versions of Power BI Desktop is the DAX Query View. Instead of creating measures one at a time using the Modeling tab, you can now write dozens—or even hundreds—of measures in a single editor, test them instantly, and commit them to your semantic model with one click.

If you’re working on enterprise dashboards or maintaining a centralized measure library, this feature can save hours of development time.

In this article, you’ll learn how to create measures using DAX Query View, test them before saving, and build reusable measure libraries for your Power BI projects.

Why Use DAX Query View?

Traditionally, creating measures required:

  • Selecting a table
  • Clicking New Measure
  • Writing one measure at a time
  • Waiting for visuals to refresh

For a few measures, that’s fine.

But imagine creating 100+ KPIs for a corporate dashboard.

DAX Query View makes this dramatically faster by providing:

  • Write multiple measures together
  • Copy/Paste entire measure libraries
  • Test calculations before saving
  • Update the model in one click
  • Better organization for enterprise projects

    Step 1: Open DAX Query View

    Open Power BI Desktop.

    From the left navigation pane, click the DAX Query View icon.

    It opens a dedicated code editor where you can write DAX queries and define measures.


    Step 2: Create a New Measure Query

    You have two options.

    Option 1 (Recommended)

    Right-click any table in the Data pane.

    Select:

    Quick Queries → Define New Measure

    Power BI automatically creates the required syntax.


    Option 2 (Manual)

    Open a blank DAX Query tab and start writing your own query.

    Example:

    DEFINE
        MEASURE 'Sales'[Total Sales] =
            SUM(Sales[Sales Amount])
    
    EVALUATE
    ROW(
        "Sales", [Total Sales]
    )

    Step 3: Create Multiple Measures Together

    One of the biggest advantages of DAX Query View is creating many measures at once.

    Example:

    DEFINE
    
    MEASURE 'Sales'[Total Sales] =
    SUM(Sales[Sales Amount])
    
    MEASURE 'Sales'[Total Profit] =
    SUM(Sales[Profit])
    
    MEASURE 'Sales'[Profit Margin %] =
    DIVIDE(
        [Total Profit],
        [Total Sales]
    )
    
    EVALUATE
    
    SUMMARIZECOLUMNS(
        Product[Category],
        "Sales",[Total Sales],
        "Profit",[Total Profit],
        "Margin",[Profit Margin %]
    )

    Instead of switching between multiple measure windows, everything stays inside one editor.


    Step 4: Test Your Measures

    Click Run.

    Power BI executes the query and displays the output in the Results pane.

    This allows you to verify:

    • Values
    • Filter context
    • DAX logic
    • Relationships

    before adding anything to your model.


    Step 5: Save Measures to Your Model

    Once the calculations are correct, Power BI provides two ways to commit them.

    Method 1: CodeLens

    Above every new measure you’ll see:

    Update Model → Add New Measure

    Click it.

    The measure becomes part of your semantic model.


    Method 2: Update Model

    If you’ve created multiple measures, simply click:

    Update Model with Changes

    Power BI saves every new measure simultaneously.

    This is extremely useful when importing large measure libraries.


    Example: Building a Measure Library

    Instead of scattered measures across different tables, many developers create a dedicated Measures table.

    Example:

    DEFINE
    
    MEASURE '_Measures'[Total Employees] =
    DISTINCTCOUNT(Employees[EmployeeID])
    
    MEASURE '_Measures'[Active Employees] =
    CALCULATE(
        [Total Employees],
        Employees[EmploymentStatus]="Active"
    )
    
    MEASURE '_Measures'[Average Salary] =
    AVERAGE(Employees[AnnualSalary])
    
    EVALUATE
    ROW(
        "Employees",[Total Employees],
        "Active",[Active Employees],
        "Average Salary",[Average Salary]
    )

    This approach keeps all business calculations centralized, reusable, and easy to maintain.


    Organizing Large Measure Libraries

    For enterprise solutions, group measures into logical sections using comments.

    Example:

    /*=============================
    Employee Measures
    =============================*/
    
    ...
    
    /*=============================
    Project Measures
    =============================*/
    
    ...
    
    /*=============================
    Financial KPIs
    =============================*/

    This makes navigating hundreds of measures much easier.


    Enterprise Best Practices

    When writing measures in DAX Query View:

    • Create a dedicated Measures table.
    • Use meaningful measure names.
    • Prefer DIVIDE() instead of the / operator to avoid divide-by-zero errors.
    • Use VAR variables for complex calculations to improve readability and performance.
    • Reuse existing measures instead of repeating calculations.
    • Test every measure with an EVALUATE statement before updating the model.
    • Organize measures into logical sections such as Sales, Finance, HR, Inventory, and Time Intelligence.
    • Add comments to improve maintainability.

    Benefits of DAX Query View

    Using DAX Query View provides several advantages:

    • Faster measure creation
    • Bulk editing of DAX calculations
    • Easier debugging
    • Better code organization
    • Enterprise-ready development workflow
    • Improved productivity for Power BI developers

    Whether you’re building a simple report or a large semantic model with hundreds of measures, DAX Query View offers a much more efficient development experience than creating measures one by one.

    Download & Copy the Complete Measure Library

    Below is a complete enterprise-style DAX measure library that you can paste directly into Power BI Desktop → DAX Query View.

    It includes measures for:

    • Employee KPIs
    • Project KPIs
    • Task KPIs
    • Performance Reviews
    • Resource Utilization
    • Executive KPIs
    • Time Intelligence
    • Budget Analysis
    • Salary Metrics
    • Milestones

    Simply copy the code below, click Run to validate the measures, then select Update Model to add all measures to your semantic model.

    /*========================================================
        TECHCORP MASTER MEASURE LIBRARY
        Best Practices Used:
        - Centralized Measure Table
        - Reusable Measures
        - Dynamic Calculations
        - DIVIDE() instead of /
        - Variables for Optimization
        - Fully Filter Context Compatible
    ========================================================*/
    
    
    /*========================================================
        EMPLOYEE MEASURES
    ========================================================*/
    
    DEFINE
        MEASURE '_Measures'[Total Employees] =
            DISTINCTCOUNT(Employees[EmployeeID])
    
        -- Active workforce count
        MEASURE '_Measures'[Active Employees] =
            CALCULATE(
                [Total Employees],
                Employees[EmploymentStatus] = "Active"
            )
    
        -- Employees no longer active
        MEASURE '_Measures'[Inactive Employees] =
            CALCULATE(
                [Total Employees],
                Employees[EmploymentStatus] = "Inactive"
            )
    
        -- Attrition KPI
        MEASURE '_Measures'[Employee Attrition %] =
            DIVIDE(
                [Inactive Employees],
                [Total Employees]
            )
    
        -- Average employee salarya
        MEASURE '_Measures'[Average Salary] =
            AVERAGE(Employees[AnnualSalary])
    
        -- Total organization salary expense
        MEASURE '_Measures'[Total Salary Cost] =
            SUM(Employees[AnnualSalary])
    
        -- Employee tenure in months
        MEASURE '_Measures'[Average Employee Tenure] =
            AVERAGEX(
                Employees,
                DATEDIFF(
                    Employees[JoinDate],
                    TODAY(),
                    MONTH
                )
            )
    
    
    
    /*========================================================
        PROJECT MEASURES
    ========================================================*/
    
        -- Total projects in organization
        MEASURE '_Measures'[Total Projects] =
            DISTINCTCOUNT(Projects[ProjectID])
    
        -- Completed projects
        MEASURE '_Measures'[Completed Projects] =
            CALCULATE(
                [Total Projects],
                Projects[Status] = "Completed"
            )
    
        -- Running projects
        MEASURE '_Measures'[In Progress Projects] =
            CALCULATE(
                [Total Projects],
                Projects[Status] = "In Progress"
            )
    
        -- Delayed projects
        MEASURE '_Measures'[Delayed Projects] =
            CALCULATE(
                [Total Projects],
                Projects[EndDate] > Projects[PlannedEndDate]
            )
    
        -- Average completion percentage
        MEASURE '_Measures'[Project Completion %] =
            AVERAGE(Projects[CompletionPct])
    
        -- Budget allocated
        MEASURE '_Measures'[Total Budget] =
            SUM(Projects[Budget])
    
        -- Actual spent amount
        MEASURE '_Measures'[Total Actual Cost] =
            SUM(Projects[ActualCost])
    
        -- Budget variance amount
        MEASURE '_Measures'[Budget Variance] =
            [Total Budget]
                - [Total Actual Cost]
    
        -- Budget variance percentage
        MEASURE '_Measures'[Budget Variance %] =
            DIVIDE(
                [Budget Variance],
                [Total Budget]
            )
    
        -- Projects exceeding allocated budget
        MEASURE '_Measures'[Projects Over Budget] =
            CALCULATE(
                [Total Projects],
                Projects[ActualCost] > Projects[Budget]
            )
    
        -- Average project duration
        MEASURE '_Measures'[Average Project Duration] =
            AVERAGEX(
                Projects,
                DATEDIFF(
                    Projects[StartDate],
                    Projects[EndDate],
                    DAY
                )
            )
    
    
    
    /*========================================================
        TASK MEASURES
    ========================================================*/
    
        -- Total tasks
        MEASURE '_Measures'[Total Tasks] =
            DISTINCTCOUNT(Tasks[TaskID])
    
        -- Completed tasks
        MEASURE '_Measures'[Completed Tasks] =
            CALCULATE(
                [Total Tasks],
                Tasks[Status] = "Completed"
            )
    
        -- Pending tasks
        MEASURE '_Measures'[Pending Tasks] =
            CALCULATE(
                [Total Tasks],
                Tasks[Status]
                    IN {
                        "To Do",
                        "In Progress",
                        "In Review"
                    }
            )
    
        -- Task completion rate
        MEASURE '_Measures'[Task Completion %] =
            DIVIDE(
                [Completed Tasks],
                [Total Tasks]
            )
    
        -- Overdue tasks
        MEASURE '_Measures'[Overdue Tasks] =
            CALCULATE(
                [Total Tasks],
                Tasks[DueDate] < TODAY(),
                ISBLANK(Tasks[CompletedDate])
            )
    
        -- Critical tasks
        MEASURE '_Measures'[Critical Tasks] =
            CALCULATE(
                [Total Tasks],
                Tasks[Priority] = "Critical"
            )
    
        -- Avg estimated effort
        MEASURE '_Measures'[Average Estimated Hours] =
            AVERAGE(Tasks[EstimatedHours])
    
        -- Avg actual effort
        MEASURE '_Measures'[Average Actual Hours] =
            AVERAGE(Tasks[ActualHours])
    
        -- Resource efficiency KPI
        MEASURE '_Measures'[Task Efficiency %] =
            DIVIDE(
                [Average Estimated Hours],
                [Average Actual Hours]
            )
    
        -- Hours variance
        MEASURE '_Measures'[Hours Variance] =
            SUM(Tasks[ActualHours])
                - SUM(Tasks[EstimatedHours])
    
        -- Tasks completed before deadline
        MEASURE '_Measures'[Tasks Closed On Time] =
            CALCULATE(
                [Total Tasks],
                Tasks[CompletedDate] <= Tasks[DueDate]
            )
    
        -- On-time delivery rate
        MEASURE '_Measures'[On Time Task %] =
            DIVIDE(
                [Tasks Closed On Time],
                [Completed Tasks]
            )
    
    
    
    /*========================================================
        PROJECT ASSIGNMENT / UTILIZATION
    ========================================================*/
    
        -- Projects per employee
        MEASURE '_Measures'[Projects Per Employee] =
            DIVIDE(
                DISTINCTCOUNT(Project_Assignments[ProjectID]),
                DISTINCTCOUNT(Project_Assignments[EmployeeID])
            )
    
        -- Avg employee allocation
        MEASURE '_Measures'[Average Allocation %] =
            AVERAGE(Project_Assignments[AllocationPct])
    
        -- Employees heavily allocated
        MEASURE '_Measures'[Highly Allocated Employees] =
            CALCULATE(
                DISTINCTCOUNT(Project_Assignments[EmployeeID]),
                Project_Assignments[AllocationPct] >= 80
            )
    
        -- Active project assignments
        MEASURE '_Measures'[Active Assignments] =
            CALCULATE(
                DISTINCTCOUNT(Project_Assignments[AssignmentID]),
                Project_Assignments[IsActive] = TRUE()
            )
    
        -- Avg task load per employee
        MEASURE '_Measures'[Employee Task Load] =
            DIVIDE(
                [Total Tasks],
                [Active Employees]
            )
    
    
    
    /*========================================================
        PERFORMANCE REVIEW MEASURES
    ========================================================*/
    
        -- Overall review score
        MEASURE '_Measures'[Average Performance Score] =
            AVERAGE(Performance_Reviews[PerformanceScore])
    
        -- Technical capability score
        MEASURE '_Measures'[Average Technical Score] =
            AVERAGE(Performance_Reviews[TechnicalScore])
    
        -- Attendance quality score
        MEASURE '_Measures'[Average Attendance Score] =
            AVERAGE(Performance_Reviews[AttendanceScore])
    
        -- Collaboration score
        MEASURE '_Measures'[Average Collaboration Score] =
            AVERAGE(Performance_Reviews[CollaborationScore])
    
        -- Goals achievement ratio
        MEASURE '_Measures'[Goal Achievement %] =
            DIVIDE(
                SUM(Performance_Reviews[GoalsAchieved]),
                SUM(Performance_Reviews[GoalsSet])
            )
    
        -- Employees recommended for promotion
        MEASURE '_Measures'[Promotion Recommended Count] =
            CALCULATE(
                DISTINCTCOUNT(Performance_Reviews[EmployeeID]),
                Performance_Reviews[PromotionRecommended] = TRUE()
            )
    
        -- Average increment percentage
        MEASURE '_Measures'[Average Salary Increase %] =
            AVERAGE(Performance_Reviews[SalaryIncreasePct])
    
    
    
    /*========================================================
        MILESTONE MEASURES
    ========================================================*/
    
        -- Total milestones
        MEASURE '_Measures'[Total Milestones] =
            DISTINCTCOUNT(Milestones[MilestoneID])
    
        -- Achieved milestones
        MEASURE '_Measures'[Achieved Milestones] =
            CALCULATE(
                [Total Milestones],
                Milestones[Status] = "Achieved"
            )
    
        -- Delayed milestones
        MEASURE '_Measures'[Delayed Milestones] =
            CALCULATE(
                [Total Milestones],
                Milestones[Status] = "Delayed"
            )
    
        -- Milestone completion KPI
        MEASURE '_Measures'[Milestone Achievement %] =
            DIVIDE(
                [Achieved Milestones],
                [Total Milestones]
            )
    
        -- Average delay days
        MEASURE '_Measures'[Average Milestone Delay Days] =
            AVERAGEX(
                FILTER(
                    Milestones,
                    NOT ISBLANK(Milestones[ActualDate])
                ),
                DATEDIFF(
                    Milestones[PlannedDate],
                    Milestones[ActualDate],
                    DAY
                )
            )
    
    
    
    /*========================================================
        EXECUTIVE KPI MEASURES
    ========================================================*/
    
        -- Executive level success KPI
        MEASURE '_Measures'[Project Success Score] =
            (
                [Project Completion %] * 0.4
            )
            +
            (
                (1 - [Budget Variance %]) * 0.3
            )
            +
            (
                [Milestone Achievement %] * 0.3
            )
    
        -- Resource utilization KPI
        MEASURE '_Measures'[Resource Utilization Score] =
            DIVIDE(
                [Average Allocation %],
                100
            )
    
        -- Employee performance index
        MEASURE '_Measures'[Employee Performance Index] =
            DIVIDE(
                [Average Performance Score]
                    + [Average Technical Score]
                    + [Average Collaboration Score],
                3
            )
    
    
    
    
    
    /*========================================================
        TIME INTELLIGENCE MEASURES
    ========================================================*/
    
        -- IMPORTANT:
        -- Create proper Calendar table
        -- Mark as Date Table
        -- Connect Calendar[Date] with fact tables
    
        MEASURE '_Measures'[Projects YTD] =
            TOTALYTD(
               [Total Projects],
                'Calendar'[Date]
            )
    
        MEASURE '_Measures'[Tasks YTD] =
            TOTALYTD(
               [Total Tasks],
                Calendar[Date]
            )
    
        MEASURE '_Measures'[Budget YTD] =
            TOTALYTD(
                [Total Budget],
                Calendar[Date]
            )
    
        MEASURE '_Measures'[Projects MOM Growth %] =
            VAR CurrentMonth =
                [Total Projects]
    
            VAR PreviousMonths =
                CALCULATE(
                    [Total Projects],
                    DATEADD(Calendar[Date], -1, MONTH)
                )
    
            RETURN
                DIVIDE(
                    CurrentMonth - PreviousMonth,
                    PreviousMonth
                )
    
        MEASURE '_Measures'[Tasks MOM Growth %] =
            VAR CurrentMonth =
              [Total Tasks]
    
            VAR PreviousMonths =
                CALCULATE(
                    [Total Tasks],
                    DATEADD(Calendar[Date], -1, MONTH)
                )
    
            RETURN
                DIVIDE(
                    CurrentMonth - PreviousMonth,
                    PreviousMonth
                )
    

     

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping