Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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

 

  • az38's avatar
    az38
    6 years ago

    Hi Anonymous 

    try

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

5 Replies

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

    • Anonymous's avatar
      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). 

      • az38's avatar
        az38
        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)