Cube.PropertyKey

D

T

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

Introduction to Cube.PropertyKey

Cube.PropertyKey is a function in Power Query that returns the property key for a given property name in a cube. It takes in two arguments:

– cube: The name of the cube that you want to query

– propertyName: The name of the property for which you want to retrieve the key

This function is often used in combination with other functions like CubeValue and CubeSetProperty to retrieve or set cube property values.

Understanding the M Code Behind Cube.PropertyKey

To understand the M code behind Cube.PropertyKey, let’s start by looking at a simple example. Suppose we have a cube named “Sales” and we want to retrieve the property key for the “Category” property. We can use the following M code:


let

cube = AnalysisServices.Database(“localhost”, “Sales”),

propertyName = “Category”,

propertyKey = Cube.PropertyKey(cube, propertyName)

in

propertyKey


Let's break down this code step by step:

1. The first line of code creates a variable named "cube" and assigns it the value of the AnalysisServices.Database function with two arguments: "localhost" (the name of the server where the cube is stored) and "Sales" (the name of the cube).

2. The second line of code creates a variable named "propertyName" and assigns it the value of the string "Category" (the name of the property we want to retrieve the key for).

3. The third line of code creates a variable named "propertyKey" and assigns it the value of the Cube.PropertyKey function with two arguments: "cube" (the name of the cube we want to query) and "propertyName" (the name of the property for which we want to retrieve the key).

4. Finally, the last line of code returns the value of the "propertyKey" variable.

Cube.PropertyKey is a useful function in Power Query that allows you to retrieve the property key for a given property name in a cube. Understanding the M code behind this function can help you to better leverage it in your data transformation and analysis tasks. With this knowledge, you can use it in combination with other functions like CubeValue and CubeSetProperty to create more powerful and efficient queries.

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)