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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
dwel0120
Helper III
Helper III

Filter Function across two tables

I have some dummy data in the two tables below.

 

I am trying to build measures with the Table 2 data but I want to filter the results to only include "banana" from Table 1. I am unable to get the filter function to work. These two tables would also be connected in my model. 

 

The goal is to count in the RipeTest column and divide the 1s (numerator) with the total count (denominator) but ONLY the bananas. 

 

 

dwel0120_1-1663684586361.png

 

1 ACCEPTED SOLUTION

I couldn't get it to work. I used KEEPFILTERS and I got it working. 

View solution in original post

4 REPLIES 4
jgeddes
Super User
Super User

Does this get you the result you are looking for?

Ripe Banana Percentage =
var _filteredProduct = "Banana"
var _ripeCount =
CALCULATE(
    COUNT(ripeTable[RipeTest]),
    TREATAS(VALUES(productTable[Product#]),ripeTable[Product #]),
    FILTER(ripeTable, ripeTable[RipeTest] = 1),
    FILTER(productTable, productTable[Product] = _filteredProduct)
)
var _productCount =
CALCULATE(
    COUNT(productTable[Product]),
    FILTER(productTable, productTable[Product] = _filteredProduct)
)
return
DIVIDE(_ripeCount, _productCount, 0)



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





I couldn't get it to work. I used KEEPFILTERS and I got it working. 

jgeddes
Super User
Super User

If you are looking for a result like

 

jgeddes_0-1663685715900.png

jgeddes_1-1663685728851.png

I created the two tables you provided, without a relationship between them, and then wrote the following measure

 

Ripe Percentage =
var _ripeCount =
CALCULATE(
    COUNT(ripeTable[RipeTest]),
    TREATAS(VALUES(productTable[Product#]),ripeTable[Product #]),
    FILTER(ripeTable, ripeTable[RipeTest] = 1)
)
var _productCount =
COUNT(productTable[Product])
 
return
DIVIDE(_ripeCount, _productCount, 0)
 
Hope this helps.

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





@jgeddes I need to filter out the bananas or the product in the measure because ultimately need a bar chart with a measure for each product.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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