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 Add My Power BI Report in My PowerPoint Presentation?

Had a great week after conducting two-day sessions on Data Warehousing and How to do Business Intelligence with Microsoft Power BI . During the sessions, I got an interesting question from the audience. The question was “how its possible to show the Power BI report or visuals in my Powerpoint slides, at the same time the data need to be up-to-date same as in report”. I love these sort of questions and find solutions because these are real-world problems they have. I thought to write a simple post to address that problem, and in this post, I explain how to achieve it. Pre-requisites You have already Power BI report created and published to the Power BI service. If you missed how to do it read this blog . If your source is a file like Excel or CSV the deployment is even simple. You don't want to worry about to configure the gateway and you can simply click Publish and publish your report. Steps to Follow Open the MS PowerPoint and go to Insert tab and My-Addins It will ...

Get Started with Azure Machine Learning

Azure Machine Learning is a Microsoft cloud solution which allow us to do end-to-end experiments using the samples, experiments provided. Further, it allows us to write custom algorithms using popular data science languages like R and Python.  Lets start to create preview account on Azure and create Azure Machine Learning Experiment workspace. Microsoft gives 30 days trial period for free to do experiments on Azure. You can start to create an Azure account from here. When you sign-up you might need to provide credit card details that only for validate the user. As far as I know we only need to pay if we are going to upgrade the free subscription for Pay-as-you-go model. Lets start to create a machine learning experimentation. For that click on left down below "More services" and from the search bar, type "Machine Learning". Then click the Machine Learning Experimentation in order to create new environment. Then it will open new blades to provide d...

How to Create a Date Table in Few Steps Using Power BI

Calendar Dimension or Calendar Table is one of the crucial table in a Power BI model. I never have seen any data warehouse data model which does not have a Calendar table so far in my development. Because, when it comes to data warehousing or dimension modeling you may storing various business processes or events as Facts. So those events anyway occur in particular date or time. So simply there wouldn’t be a Power BI data model without a date table. In this post, I’m going to share with you how to create a date table within few steps. Actually, there are two DAX measures which we can use to create a date table. Calendar(DAX) and CalendarAuto(Auto). Calendar(DAX) = You can pass start date and End date as parameters you need to create date table. CalendarAuto(DAX) = You can use this function without passing any parameter. Then it will generate the dates based on your data model dates.  You can simply copy the below DAX code and paste in your Power BI Desktop DAX e...