Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Isoka
Frequent Visitor

Filter based on a condition

Dear all,

 

I can't figure out how to apply a filter based on a condition. For instance, I would like to filter column "Area" from table "A" based on column "Area" from table "B". But I want to use this column in a SELECTEDVALUE statement so that if column "Area" from table "B" is not blank, then column "Area" from table "A" will be filtered. The idea is that if there is a blank cell there will be no filter for that specific column. I have put it here in a simple way but there will be a big table with many columns from where the SELECTEDVALUE will come from and I need to make this DAX as generic as possible.

I tried and IF statement inside a measure with the filter being one of the results but it is not allowed. 

Any help will be appreciated 🙂

Best regards,

 

Isoka

 

Table A:                                                                                           

SellerIDAmountArea
John1100A
Mark2200B
Paul3300C

 

Table B:

SelectedvalueArea
1A
2 
3B
1 ACCEPTED SOLUTION
Isoka
Frequent Visitor

I have just found out that writing the code with the whole CALCULATE inside de IF statement it works. Like this:

mymeasure = IF (1=1,

                           CALCULATE(

                                                SUM(),

                                                FILTER()

                                               ),

                                               result if false

                            )

 

But if someone has a more elegant way to accomplish what I have explained in the first post I would really like to learn.

Best regards,

 

Isoka

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Isoka , Not very clear, share the expected output with example

you can create a measure like this for table B

 

countrows(filter(TableB, TableB[Selectedvalue] in allselected(TableA[Area]) ) )

 

also check

https://docs.microsoft.com/en-us/dax/treatas-function

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Dear @amitchandak , thank you for your interest!

 

Let me bring this closer to the reality, I apologize for being to generic.

I used a table like the one below and put column "Country" in a slicer.

Table _SegGeral2:

CountryIn_Out1In_Out2In_Out3In_Out4
Brazil    
Germany1023935
USA6062  
Colombia    
Denmark324650 

 

Then I created the following measure to sum values on table "QUOTE_REPORT" :

Sum(QUOTE_REPORT[Value]
IF(SELECTEDVALUE(_SegGeral2[In_Out1])<>"",
Filter(QUOTE_REPORT,[In_Out] IN {SELECTEDVALUE(_SegGeral2[In_Out1]),SELECTEDVALUE(_SegGeral2[In_Out2]),SELECTEDVALUE (_SegGeral2[In_Out3]),SELECTEDVALUE(_SegGeral2[In_Out4])}))
)
Table QUOTE_REPORT:
ValueIn_OutCond2Cond3
3010xg
6580yd
79663sr
3446dt
21450qt
375103et
2910fy
78550sg
99292sn

 

In the fact table there will always be a value in column "In_Out" but in table "_SegGeral2" column "In_Out1" there may be blank values.

The expected result is that when I select Brazil in the slicer, since there is no value in column "In_Out1", the filter will not be included in the SUM statement. But when I select Germany it must be included.

I will have the same situation for "Cond2", "Cond3" and a few other conditions. That is why I am trying to find a way to include a filter, inside a SUM statement, conditioned to the existence of values in certain columns on the dimension table.

Hope I was able to make it clearer.

Best regards,

Isoka
Frequent Visitor

I have just found out that writing the code with the whole CALCULATE inside de IF statement it works. Like this:

mymeasure = IF (1=1,

                           CALCULATE(

                                                SUM(),

                                                FILTER()

                                               ),

                                               result if false

                            )

 

But if someone has a more elegant way to accomplish what I have explained in the first post I would really like to learn.

Best regards,

 

Isoka

Anonymous
Not applicable

Hi @Isoka ,

Thank you for sharing, is there anything else you need help with regarding this thread? If not, would it be possible to mark your reply as Answered? This will also help the others in the community who have similar problems to yours to find a solution as soon as possible. Thank you.

By the way, about Table _SegGeral2, maybe you can select all in_out columns and unpivot them in Query Editor first as in the figure below, so that it may be more convenient to calculate later.

yingyinr_0-1646645111004.png

Best Regards

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors