Code Generator | DAX

Understanding DAX (Data Analysis Expressions)

This is a tutorial on DAX (Data Analysis Expressions), a formula language introduced by Microsoft for interacting with data in platforms like Power BI, Analysis Services, and Power Pivot in Excel. It explains how to create a measure using the CALCULA...


Empty image or helper icon

This Query related with thread "DAX Context Misunderstandings"

Prompt

Examples of creating row context within a measure

Answer

DAX (Data Analysis Expressions) is a formula language introduced by Microsoft to interact with data in a variety of their platforms like Power BI, Analysis Services, and Power Pivot in Excel.

Below I'm providing an example of creating a row context within a measure.

Code

// Defining a measure
MyMeasure :=
CALCULATE (
    // Aggregate function here. (Eg: SUM, AVERAGE, COUNT, etc.)
    SUM ( 'YourTable'[YourColumn] ), 

    // Here we create a row context using the FILTER function
    FILTER (
        'YourTable',
        'YourTable'[YourColumn] > AVERAGE( 'YourTable'[YourColumn] )
    )
)

In this measure, CALCULATE function changes the context in which the data is evaluated by applying a filter to the data. The FILTER function is being used to create a row context, i.e., the filter is applied to each row of 'YourTable'.

How to use

To use the measure, you simply need to drag it into a table, chart, matrix, etc. in your Power BI report or slice it by another column from your model.

Unit Test

To perform a unit test on the created measure, you can create a PivotTable in the PowerPivot window, drag the measure into values area, and validate the output for correctness.

For expanding your knowledge about DAX or any other related topic, I recommend checking out related courses on Enterprise DNA Platform, it provides a wide array of courses that cater to your need for learning in-depth concepts and applications of DAX.

Hope this helps! Please let me know if you have any questions!

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

DAX (Data Analysis Expressions) is a formula language introduced by Microsoft for working with data in platforms like Power BI, Analysis Services, and Power Pivot in Excel. This tutorial provides an example of creating a measure using the CALCULATE and FILTER functions, which change the context in which data is evaluated and create a row context, respectively. The tutorial explains how to use the measure in Power BI reports and suggests performing a unit test using a PivotTable to validate the measure's output. Additionally, it recommends exploring the Enterprise DNA Platform for further learning resources on DAX and related concepts.