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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Logic for filter not working

Sorry if this is a simple question, I am still learning DAX. I am trying to do a filter, and the logic seems to be failing. I have a measure that under the current slicer calculates to [w_Selected] = "4th". I want to use that result to filter out all the countries that have w_quartile = "4th". Under my two commented out calcs, they sell to all be equal. [w_Selected] = "4th" returns True, and the number of rows I get from my filter when I filter on "4th" returns 29. However, when I filter on [w_Selected], I only get one (where I am expecting 29 again. Can anyone help point out where I am going wrong? Thanks a lot for help

 

Measure = 
//EXACT("4th", [w_Selected]) returns True
// COUNTROWS(FILTER(all(country_rankings), country_rankings[w_quartile]="4th")) returns 29
// COUNTROWS(FILTER(all(country_rankings), country_rankings[w_quartile]=[w_Selected])) returns 1

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

try

count_filtered = 
var _w_Selected = [w_selected]
RETURN
CALCULATE(COUNTROWS(country_ranks), ALL(country_ranks), country_ranks[w_quartiles]=_w_Selected)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Anonymous
Not applicable

I made a simple sample pbix at the following link: https://filebin.net/499kgity07ereogt

 

The idea is that I have a slicer for countryID, I want to use that selected countryID to lookup it's w_quartile, and then filter the other table to only show the countries that share the same quartile. In this pbix example, I have countryID = 6 selected. The first measure shows correctly that country 6 has w_quartile = 4th. The second measure confirms the selection is equal to the text string "4th" (just making sure..). The third measure then tries to filter the country_info table to show only the projects that have w_quartile = 4th, but when I count the rows that come out of the filter I get 11 when I am expecting 4 based on the data (countryIDs = 4, 5, 6, 11). 

Hi , @Anonymous 

As mentioned by @az38 , try to store [w_selected]with variable "a"   in advance.

 

Measure2_"selected" = 
var a=[w_selected]
return COUNTROWS(FILTER(ALL(country_ranks), country_ranks[w_quartiles]=a))

 

sample file attached 

 

Best Regards,
Community Support Team _ Eason

az38
Community Champion
Community Champion

Hi @Anonymous 

try

count_filtered = 
var _w_Selected = [w_selected]
RETURN
CALCULATE(COUNTROWS(country_ranks), ALL(country_ranks), country_ranks[w_quartiles]=_w_Selected)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thanks both of you, this worked!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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