Cube.MeasureProperties

D

T

The M Code Behind the Power Query M function Cube.MeasureProperties

What is Power Query?

Before we dive into the M code behind Cube.MeasureProperties, let’s first define what Power Query is and what it does. Power Query is a data transformation and cleansing tool that is part of the Power BI suite. It allows you to connect to various data sources, transform the data, and load it into a data model or visualization tool like Power BI.

Power Query is a versatile tool and offers a wide range of transformation functions, including splitting columns, merging tables, filtering rows, and aggregating data. One of the key features of Power Query is its ability to work with multidimensional cubes, which is where the Cube.MeasureProperties function comes in.

What is Cube.MeasureProperties?

Cube.MeasureProperties is a Power Query M function that allows you to retrieve the properties of a measure in a multidimensional cube. Measures are calculations in a cube that aggregate data, such as summing or averaging sales by product or region. Cube.MeasureProperties allows you to retrieve information such as the measure name, format, and description, which is useful when building reports or analyzing data in Power BI.

The syntax for Cube.MeasureProperties is as follows:


Cube.MeasureProperties(cube as cube, measureNameOrExpression as text)


The function takes two arguments:

- cube: A multidimensional cube.

- measureNameOrExpression: The name of the measure or an expression that evaluates to the measure.

The function returns a record containing the properties of the measure.

The M code behind Cube.MeasureProperties

Now that we've covered what Cube.MeasureProperties does, let's take a look at the M code behind it. The M code for Cube.MeasureProperties is as follows:


let

measure = Cube.CubeExpression(cube, measureNameOrExpression),

properties = measure{0}[MEASURE_PROPERTIES]

in

properties


Let's break down this code line by line:

#### Line 1: Declaring the measure variable


let

measure = Cube.CubeExpression(cube, measureNameOrExpression),


The first line of the M code declares a variable called "measure" and assigns it the result of the Cube.CubeExpression function. This function retrieves the expression for the specified measure in the cube.

#### Line 2: Declaring the properties variable


properties = measure{0}[MEASURE_PROPERTIES]


The second line of the M code declares a variable called "properties" and assigns it the value of the "MEASURE_PROPERTIES" property of the first item in the "measure" variable. This property contains the measure properties that we want to retrieve.

#### Line 3: Returning the properties variable


in

properties


The final line of the M code returns the "properties" variable, which contains the measure properties.

Cube.MeasureProperties is a powerful function in Power Query that allows you to retrieve the properties of a measure in a multidimensional cube. By understanding the M code behind this function, you can gain a deeper understanding of how it works and how you can use it in your data transformations. In this article, we've broken down the M code behind Cube.MeasureProperties and explained each line in detail. Armed with this knowledge, you can take your Power Query skills to the next level and build more powerful data models and visualizations.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)