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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

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

@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.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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