Skip to main content

How to Filter Multiple Values in Same Column using DAX

When you working with Tabular modeling projects you may encounter this problem. How we can filter multiple cell values that are in the same column using DAX for creating measure.

Scenario:

Let's say you have a table with Sales data as below. Which contains Product information and sales amounts.


Assume, you have a requirement to create a Calculated Measure to filter only Clothing and Accessories. Of course, you can do this using a filter pane as shown below.

Remember this requirement is not to have multiple predicates with different columns but, in the same column.

Solution:

We can write a DAX code like this to solve this problem. In here I create a Calculated Measure called Other Products which filters all the records in Sales query for Category Accessories and Clothing.

EVALUATE
CALCULATE (
    SUM ( Sales[Sales Amount] ),
    FILTER ( Sales, Sales[Category] IN { "Accessories", "Clothing" } )
)


You can achieve the same results like you had earlier through this.



Conclusion:


This is an alternative way of filtering multiple predicate logics in the same column using DAX. Sometimes you may find this as a very useful method especially if you are working with Finance related calculations, Chart of Account. Let us know what you think about this and would like to hear your feedback. 

Comments

Post a Comment

Popular posts from this blog

How to Visualize Images Dynamically using Microsoft Power BI

One of the challenging part of the Power BI report development is handling dynamic images. We can add a static image within few steps and it is pretty straightforward. But, when it comes to dynamic images, available options are countable. Available options: Upload to the Web : You can upload the images to the web and use the image URLs as a reference. But, you need to make sure the data category  of your column where to store the image URL make it as  I mage URL. When we are dealing with clients data we cannot upload it to the public web. So, need to be accountable for data we are dealing with. Azure Blob Storage : If the security is the concern, you can use Azure blog storage to store image files. Only accessible who are in the same domain or security group. You have the full control over managing the authorization. I have an experience of, there are clients they never want to upload any data to the cloud. And if we are dealing with multiple clie...

Run T-SQL Script Files Using Command Line

Most of the time when we need to execute a SQL script or statement, then we go for SQL Server Management Studio to execute our T-SQL scripts. But the same result we can achieve using Command Prompt. This is very simple way to do that just a matter of write a command and pass few arguments. You can see the process status like as in when you execute a query in Management studio. Use-case : There may be having some situations you won't be able to execute T-SQL script using Management Studio. Most of the time when doing data population. In my case, I had a situation I needed to populate a Database without using backup/restore. Once I generated script with all the schemas and related data it took around 400+Mb sql file.  SQL Server Management Studio will not allow you to run the script unless you execute the query in high-end box. Because, when the file loaded to the memory it will too hard to cater our requirement. You may probably get  memory ...

Jump Start with Azure Databricks - Chapter 1

Azure Databricks is the latest and greatest way of processing Big Data in Azure cloud. It is an apache spark based analytics platform allow users to setup spark clusters with few clicks, streamlined workflows, collaborate with data engineers and data scientists. I’ve started to write a set of short articles to demonstrate step-by-step how to engage with Azure Databricks. As the first step, you will find how to get into Azure Databricks. Article 1: How to Create Azure Databricks Workspace How to Create a Azure Databrick Workspace Summary This is the first one of article series: Jump Start with Azure Databricks. In this context, I try to cover high-level aspects of how to getting started and play around with the databricks on Azure.  Please, leave a comment below your feedback, which will greatly help to improve my future work.