Skip to main content

Filter v/s Keepfilters in DAX

Do you struggle to spot the difference between different types of filters that are available in Power BI? It can turn out to be vague for beginners in Power BI. In today's article, we will refer to these filters and explain the purpose of each one of them. If you are a novice to Power BI then you must refer to our previous blog which covers an overview of different filters that exist in Power BI. (Different Filters in Power BI).

As most of you are aware there are countless methods to attain the same result using DAX but the key thing to keep in mind is the efficiency of the DAX formula in that particular situation. For this article I am using Sample Superstore data (you can download it from kaggle.com). I will demonstrate the purpose of every formula.

Let's get started!!! so the basic idea is to calculate sales for every sub-category and by using the filter formula I need to see sales in the corporate segment. 

The above-mentioned formula is the basic approach where you just specify the field (sales in this case) and the filter you need to apply to that field but if you are considering the performance of this formula then I would say there are better formulas that will perform much better when the dataset is quite large (millions of rows). What if I need another filter that is based on the region?? Another drawback is you can only refer to a single column filter in this formula but if you need to add multiple filter conditions then this formula won't provide the desired result.

The most interesting formula to attain the same result is via using the filter. The formula is quite similar to the basic formula and allows to add multiple filter conditions with two different fields present in the same table. 
You can another filter condition apart from the segment just by adding && and the 'Orders'[Region]="East" {another condition}. This is suitable to compare different columns and measures

ProTip- If you are a beginner you should know the difference between filter and filters in DAX. Filters will return the whole table based on the applied filter so if I am applying this formula Filers('Orders'[Region]) then you will get only the different regions in that table. The values will be distinct. For more pro tips do follow us.

The last formula to achieve the same result is Keepfilters which is the most efficient and faster formula even with the multiple filter scenarios. It will keep the current filter and does not result in blank values. This can be look upon as an alternative to filter and all but the performance of keep filters is much better. Let's check how does the formula for keep filters look like.

All the three formulas provide the same result but when it comes to the performance I will prefer the keep filters but this choice can be subjective according to the situation. Keep filters is not a good choice when it comes to comparing the different columns. But it is more precise as compared to others on larger datasets.


Thanks for Reading  Let's connect on  LinkedIn. For more such blogs do follow us.

Comments

Popular posts from this blog

Ultimate Beginners Guide to DAX Studio

There are zillions of external tools available with Power BI but DAX Studio is one of the most commonly used tools to work with DAX queries. It is a perfect tool to optimize the DAX and the data model. In this blog let's shed some light on the basic functionalities that can take your report to the next level. ARE YOU READY?  To start you will need the latest version of the DAX Studio. You can download it from their website . Don't worry you don't have to pay for the license. Fortunately, DAX Studio is a free tool As a BI Developer, I am using DAX Studio regularly. Based on my experience I use it for several purposes but in this blog, I will highlight the most common ones. Extracting a dump of all the measures used in your PBIX. Why do we need to do this? It can be used for documentation purposes also sometimes we try to reuse the DAX and such a dump comes in handy in this scenario. How to achieve it? Open the DAX Studio it is located under the external tools once you open t

Append v/s Merge in Power BI

Let's discuss another problem of the week. As a Power BI user, there are times when you want to combine queries. What are the ways to do so? In most cases, you can attain it by using either append or merge and both serve different purposes. Let's understand what do these terms mean in Power BI and how they are functionally different from each other.  It is quite common to get data from various sources and you need to combine those data depending on a particular column which is common in both tables so that you can add extra information or column to your big table. In such cases, we use merge queries. How to perform merge queries? For instance, I am considering Sample Superstore data and we will merge the returns table to the order table. You will find both merge and append in the home tab in extreme right in the power query editor. ProTip - You will find two options when you click on the drop-down in merge which are merge queries and merge queries as new. When you use merge que

Use Relationship in DAX

Data modeling is an essential part of creating perfect visuals. While creating complex data models there can be a case where you can find an inactive relationship represented by dotted lines and it occurs because you already have an active relationship between the two tables. But as a developer, you need to use both the relationship. How can it be done? You can use "Use Relationship" in such cases. Use relationship can be added to your DAX and act as a modifier or enhancer for calculation. It activates the inactive relation. But make sure you have an inactive relationship in place before using the use relationship function. Let's see how it works on Sample Superstore data. In my fact table I have two dates- Order date and Ship date. I am making the two relations between my date table and fact table. The relation between the sample superstore (date) to date table (date) is active while the relation between the sample superstore (ship date) to date table (date) is inactive