Forum Discussion

abukapsoun's avatar
abukapsoun
Post Patron
3 years ago
Solved

Returning a value based on a search range

Hi,

 

I am looking for your help finding out the DAX formula to create the following scenario.

thank you

 

NameCountryNew Column  
AAXXif AA has XX in country column, then return XX, else others.  
AAOthersif AA has XX in country column, then return XX, else others.  
AAOthersif AA has XX in country column, then return XX, else others.  
BBXXif BB has XX in country column, then return XX, else others.  
BBXXif BB has XX in country column, then return XX, else others.  
BBOthersif CC has XX in country column, then return XX, else others.  
CCOthersif CC has XX in country column, then return XX, else others.  
  • rajulshah's avatar
    rajulshah
    3 years ago

    abukapsoun ,

     

    Please see if the following DAX resolves your issue:

    Column =
    CALCULATE ( MAX ( [Country] ), ALLEXCEPT ( Countries, Countries[Name] ) )

7 Replies

  • rajulshah's avatar
    rajulshah
    Resident Rockstar

    abukapsoun ,

     

    Please try the below DAX formula. Please know that I have assumed that you want if there is any country present then we should get the value of country else Others.

    Column =
    IF ( [Country] <> "Others", [Country], "Others" )

     

    Please let me know if this is not what you want.

  • Hi Rajul, but you haven't taken into consideration the Name in the formula?

    • abukapsoun's avatar
      abukapsoun
      Post Patron

      rajulshah the result is not as expected. I want to get XX, if it exists in the whole range of countries for Name=AA

      so for each name, the formula should look into the whole range of country column, and if XX is found at least once, then return XX. 

       

      AA might have multiple lines, however in the country column it is either XX or others. So I want to do a kind of search, and if XX is found once, then return XX

      • rajulshah's avatar
        rajulshah
        Resident Rockstar

        abukapsoun ,

         

        Please see if the following DAX resolves your issue:

        Column =
        CALCULATE ( MAX ( [Country] ), ALLEXCEPT ( Countries, Countries[Name] ) )