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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
numersoz
Helper III
Helper III

DAX Filter A Table by Another Table

Hi,

I have a table where I need to average out time stamped values. I want to filter this table by the product ID's contained in another table. Both the time stampped table and the other table contraining product ID's are related using a product lookup table.

 

I've treid to use CALCULATE, but I keep getting errors. I know I can make this work if I type in all the product ID's manually, but obiously this is not practical. 

Any tips?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@numersoz , Try like

calculate(sum(table1[Values]),filter(Table1, Table1[Product ID] in Values(Table2[Product ID])))
calculate(sum(table1[Values]),filter(Table1, Table1[Product ID] in allselected(Table2[Product ID])))

 

or try treatas

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

5 REPLIES 5
numersoz
Helper III
Helper III

@Greg_Deckler @pranit828 

 

Hi,

 

Measure = CALCULATE(AVERAGE('Data Hourly'[Amount]), EXCEPT(VALUES('Data Hourly'[productName]), VALUES('Target'[productID])))

My tables are as such:

 

  • Data Hourly:
    • timeStamp
    • productName
    • Amount
  • Target:
    • productName
    • productID
    • target
  • productTable:
    • productName
    • productID

 

Data Hourly has one to many relationship with productTable using productName.

 

productTable has one to one relationship with Target using productID.

 

I want to plot amount and target, however as target table does not have all of the products, I want to plot only for the product's that exists in the target table. The problem I have is, the plot of amount is also showing products that are not part of the target table.

 

 

amitchandak
Super User
Super User

@numersoz , Try like

calculate(sum(table1[Values]),filter(Table1, Table1[Product ID] in Values(Table2[Product ID])))
calculate(sum(table1[Values]),filter(Table1, Table1[Product ID] in allselected(Table2[Product ID])))

 

or try treatas

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak 

 

Thank you! This worked.

pranit828
Community Champion
Community Champion

Hi @numersoz 

Please post sample i/p  and o/p data.

 

My hunch is that it is due to the way your table is joined. either one to many or many to many.





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile
Greg_Deckler
Super User
Super User

@numersoz - Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.