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...

Identify and Delete Unused Columns & Measures

Heavy dashboards and a bad data model is a nightmare for every BI Developer. Heavy dashboards can be slow due to multiple reasons. It is always advised to stick with best practices. Are you still figuring out about those best practices then you should definitely have a quick read on Best Practice Analyser ( link ). One of the most common issues with slow dashboards is unused columns and unused measures.  It is very normal to load some extra columns and create some test measures in your dashboard but as a part of cleanup process those unused columns and unused measures should be removed. Why we are removing them? Because if you keep them then ultimately it will increase the size of your data model which is not a good practice.  How to identify the culprits (unused columns and unused measures)? In today's blog we will provide you with 2 most common external tools which will help you in identifying the culprits. More external tools😒. Who's going to pay for this? To your surprise...

Best Practice Analyser (BPA) Guide

Do you want to save tons of efforts to check if your data model and PBIX file follows the standard best practices and norms? Then this blog is for you. If you are a follower of our channel we already deep dive into the importance of the DAX Studio as an external tool. If you are a beginner I would highly recommend to visit this blog . In today's blog we will check how Tabular Editor can help to optimize the data model.  Best Practice Analyser allows to define or import best practices. It will make sure that we do not violate the best practices while developing a dashboard. Isn't it exciting!! Before we start make sure you already have Tabular Editor version 2.24.1 installed on your system. To install it do visit this link and select the link for windows installer. Once Tabular Editor is installed it will reflect in your PBIX file under external tool. Also, we need to define the standard rules. To do so in your advanced scripting or C# script copy this and save it via Ctrl+S. An...