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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
SG_17
Frequent Visitor

Filtering rows in one table by values from another table

Hi, relatively new user trying to complicate my own life with difficult tasks. lol.  I need some help with filtering out rows from a data table (Table A) based on matching IDs from a lookup table (Table B). I would prefer to do this with a measure rather than through a creating a new table to minimize data redundancy. I would like to have both with and without the filter to be shown in different columns on the report. I think this can be better explained via visualization in my example below:

Table A

IDCostRevenue
1124
1235
1337
14511

 

Table B (discontinuation)

ID
11
12

 

Matrix on report:

 Before DiscAfter Disc
Total Cost138
Total Revenue2718

 

Any recommendations?  Thank you!!

1 ACCEPTED SOLUTION
SG_17
Frequent Visitor

I figured it out: 

CALCULATE(sum(Table A[Total Cost]),EXCEPT(VALUES(Table A[Product_ID]),VALUES(Table B[Product_ID])))

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @SG_17 

edhanss way is good. And you may try my way.

I build a table as below.

1.png

And build two measures to achieve your goal.

Total cost = IF(MAX('Table'[Statue])="Before",SUM(A[Cost]),CALCULATE(SUM(A[Cost]),FILTER(ALL(A),NOT A[ID] IN VALUES(B[ID]))))
Total Revenue = IF(MAX('Table'[Statue])="Before",SUM(A[Revenue]),CALCULATE(SUM(A[Revenue]),FILTER(ALL(A),NOT A[ID] IN VALUES(B[ID]))))

Use measures to build a matrix, and select show on rows in Values.

Result:

2.png

You can download the pbix file from this link: Filtering rows in one table by values from another table

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

amitchandak
Super User
Super User

@SG_17 , Try treatas

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

https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax/

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
edhans
Super User
Super User

I would just bring in one table. Merge Table B to Table A and create a Discontinued column. Then you can have very simple measures that just total revenue and costs with this:

 

Total Revenue = SUM('Table A'[Revenues])

Total Cost= SUM('Table A'[Cost])

 

edhans_0-1596155284854.png

See my PIBX attached. Note that in the Matrix settings I had to tick the Show the Values on the Rows setting. That is not the default. You can see in the Power Query (Transform Data) part where I merged the tables to just create a True/False field for the Discontinued. You can change that formulat to show "Discontinued" and "Not Discontinued" vs the true and false values there.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
SG_17
Frequent Visitor

Thank you for your help. I'm not sure if that can work though.  Table A has multiple instances of the ID that are added daily (the table is updated weekly), while Table B has one instance of each ID and changes (not necessarily all IDs) quarterly. Timing would also play a factor in how the discontinuation is applied. To provide a little more clarity, I used the term discontinuation, but really we offer different plans that provide for the ability to opt-out of specific products based on a given plan for reduced costs. This opt-out product list (plan) is generated quarterly.  The goal of this analysis is to see the change in costs and revenues when a client wants to opt-out to determine overall pricing.  The way that we calculate this is that we apply this opt-out plan to a clients previous product order history (Table A is total product orders) to tell them the savings from opting out.  Accordingly, I would prefer to just update the data tables (Table A weekly and Table B quarterly), rather than having to re-create merged tables.   

Here's a little more clarity via example:

 

Table A

Order_dateProduct_IDCostRevenue

1/1/2020

12358
1/2/2020111715
1/3/20202311020
1/3/202022235
1/4/202012358

 

Table B

YearQuarterProduct_ID
2020Q1123
2020Q1222

 

Output

 Total costTotal revenue
Opt-in3056
Opt-out1735
SG_17
Frequent Visitor

I figured it out: 

CALCULATE(sum(Table A[Total Cost]),EXCEPT(VALUES(Table A[Product_ID]),VALUES(Table B[Product_ID])))

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors