Skip to main content

DAX for Data Revolution


In my day to day work I work with DAX, it is a routine for me to create measures and query data for the user requirements, in my personal experience DAX allows to see what you can not simply see, it's a revolution of identifying what do you have in your hands, so I thought of highlighting few points and elaborating more on the usage of DAX. 

First and foremost the important fact is there are three types of calculations that can be defined using DAX in a model and they are as following.

1.       Calculated Columns
2.       Calculated Tables
3.       Measures

Even though we have both MDX and DAX for querying if we are adding a logic to the model it can only be achieved by DAX,

Dax can also be used to add row level security, if we consider Power BI we can create roles and assign those roles with restricted data.

For an example if we have regional data for China, United States and Japan and we need to allow Jhon to access only the data for China we can create a role

[Region] = “China”

And assign this for Jhon, so it creates a row level security and it will only provide the access for the data rows which has China for the column “Region”. Wow you are securing your data.

DAX formulas can only refer three things they are.

1.       Tables- These can be referred with single quote like ‘Sales’

2.       Columns- These can be referred along with a table or even alone when the measure is created within a table like ‘Sales’[Sales Amount] or [Sales Amount]

3.       Measures- These are expressed in square brackets – [Sales performance]

This means they have no understanding of KPI or hierarchies, but using the above you can create a perfect environment for these specific measures, do not worry because all are under hood and you have the power full BI tools such as Power BI. Next in terms of context there are primarily three types of contexts we can use in the data models.

1.       Row
2.       Query
3.       Filter

A row context includes all the values from all columns in the current row. There are two cases, first when there is an active row context. We can evaluate a calculated column or DAX function that iterates over a table.

A query context refers to the subset of data that is implicitly retrieved from a formula, It is retrieved for the all the cells that are referenced.

Filter context is used to modify the context in a formula, it is added to specify filter constraints on the set of values allowed in a column/table, by using arguments to the formula.

Then in DAX “Calculate” is a very powerful and useful function, this evaluates a context modified by a specific filter, here a filter can be

1.       Boolean Expression
2.       Table Expression

Boolean expressions are based on a single column like shown below.

CALCULATE([Sales], Product[Color] = “Red”)

This will filter the data which has the product color red and do calculations on top of it.

Table expressions will return a table and we can use context modifications such as.

CALCULATE([Sales], ALL [ProductColor])

this will fetch all the data ignoring the filters already applied on the Product Color.

Very importantly DAX allows time intelligence, we can do time based calculations such as year to date calculations. It is important to have a table marked as "date" data type in order to use these time intelligence functions.

This will be a brief intro to the world of DAX, simply DAX is a very power full query language which can be used to analyze the data in Excel or Power BI. So using DAX in the right time will help you to discover the hidden truth within your data.







Comments

Post a Comment

Popular posts from this blog

Choosing color scheme for Power BI reports

Choosing beautiful colors for an attention seeking Power BI report is always challenging. Sometimes we may have an important message but it might go unseen if proper color scheme is not used, so it is important to create reports which are informational and visually appealing. In this blog our main objective is to get an idea about selecting appropriate color scheme and tools that can be beneficial to do this. What is a color scheme? As you all know not all colors look great together and you can tell stories by just having only two colors, have a look at the following image, there in the middle you can see a circle with same color and same dimension, only thing that changes is the back ground, but depending on the back ground the way you see those circles are totally different. Some small circles appear softer, some appear sharper, and some are brighter also you might notice movements or depth effect too. It is important to choose colors wisely to serve the purp...

Five tips to enhance a tableau model with usability features.

In the previous blogs I was more focused in Power BI since i work with it day to day, but this time we are going to dig into increasing the usability features of tableau. This blog revolves around the end-user simplicity, if a model is hard to comprehend then it will be a disaster, so we should deploy some means to stay simple. So without further ado lets head on to the first topic of the day. Configuring table and  column  properties. A model can consist of many tables but the important fact is they have to be unique and it is better if we can have a table description to elaborate on whats it about. This can be also considered as an internal documentation, when a project member is changed it is easy to pick up and continue. We use connections to load data for the tables and we have a connection name for it but once if we set the source it cannot be changed in the latter part, so be mindful because once you are dropping a connection you are losing all th...

Ragged hierarchy in Power BI

Case- I have a data set which has to be visualized in a ragged hierarchy. What is ragged hierarchy A ragged hierarchy is a user defined hierarchy with an uneven number of levels.   You can see the above table which has 5 levels of hierarchy. In the first level we only have “World” as a category then moving forward to the next level we have two categories  namely “UK” and “USA” likewise the level of hierarchy is drilling down up to five levels with an uneven amount of categories. Creating a hierarchy in Power BI In the above image  you can notice that I have right clicked the “level 1” column which has to be the first level of our hierarchy, Once it is right clicked there you will notice “New hierarchy” as the second option then you will have to click that in order to create a new one. As you can notice in the above image once I have created a new hierarchy then a new column is created named “Level 1 Hierarchy” in that I have d...