Forum Discussion

bswank31's avatar
bswank31
Helper II
3 years ago

Ranking

Hi. Is there a way to Rank a specific column (GXT) but if there is an "Including" in the Category Column then keep those intervals together?

I hope someone can help me. Thanks a bunch!

 

Example:

DateSiteProjectholecategoryFrom mTo mGXT
8/14/2023BSAug1 17.821.910.8
8/14/2023BSAug1 3234.47.3
8/14/2023BSAug1 124.4129.112.9
8/14/2023BSAug3 34.140.222.7
8/14/2023BSAug3Including37.440.217
8/14/2023BSAug3 215.2219.321.4
8/14/2023BSAug4 85.390.924
8/14/2023BSAug4Including87.390.919.8
8/14/2023BSAug4 103.6106.78.6
8/14/2023TSJul1 107.4113.130.8
8/14/2023TSJul1Including107.4110.823.1
8/14/2023TSJul2 50.957.342
8/14/2023TSJul2Including50.953.325.2

24 Replies

  • if there is an "Including" in the Category Column then keep those intervals together?

    It is not clear what you are trying to achieve. What is the expected outcome based on your sample data?

    • bswank31's avatar
      bswank31
      Helper II

      Yes. If category has "Including" then keep that interval with the one it belongs with:

      I would like to be able to rank the highests GXT. If there is an "Including" then give it the same rank as the interval it belongs to. Here is the code I am using but it is not quite right:

      Ranking 1 =
      VAR current_category = SELECTEDVALUE( 'Sheet1 (2)'[Category])
      VAR gxt = SELECTEDVALUE('Sheet1 (2)'[GXT])
      RETURN
      IF( current_category = "Including",
          CALCULATE( RANK.EQ( gxt, 'Sheet1 (2)'[GXT], DESC), FILTER( ALLEXCEPT('Sheet1 (2)', 'Sheet1 (2)'[Date],'Sheet1 (2)'[Site]),'Sheet1 (2)'[Category] = "Including")),
          CALCULATE( RANK.EQ( gxt, 'Sheet1 (2)'[GXT], DESC), FILTER( ALLEXCEPT('Sheet1 (2)', 'Sheet1 (2)'[Date], 'Sheet1 (2)'[Site]),'Sheet1 (2)'[Category] <> "Including")))
      (This was from another person helping me)
       
      The output isn't putting the includings where they belong and the ranking is all messed up. It also is not filtering correctly when I select my years slicer.

      Your help is much appreciated! 


       

      • lbendlin's avatar
        lbendlin
        Super User

        sorry, still not clear to me, especially what you mean by "the interval it belongs to" - please explain what that means.

         

        What is the expected outcome based on your sample data?

  • so rank will change based on the slicer selection, correct?

     

    for 2nd answer, it means each row is a unique row. Stay tuned! Will send the solution soon. Going for a run 😃

    • bswank31's avatar
      bswank31
      Helper II

      Ya, I would like to be able to not use a slicer and see what the ranks are and also use the slicers and see the ranks. I Will most like use the year slicer the most but would like the option to use the site and month slicers also. Thanks so much for looking into this!! 

  • bswank31 that's the problem, and I don't expect it will work with different selections in the slicer.

     

    Here is the advice: There are always many ways to solve a problem, but the experts always suggest, following best practices and keeping your DAX simple by doing the heavy lifting on preparing the data and having a good model. Sometimes we go down this rabbit hole of solving a problem by writing a complex DAX which either doesn't perform or does not give the correct result. 

     

    So the solution which I gave you is super simple because we have done the work on preparing the data to achieve the goal, it will perform on large data and it is super simple code. Now the choice is yours. Good luck!

    • bswank31's avatar
      bswank31
      Helper II

      alright. Thanks so much for your help. It is greatly appreciated! 

  • bswank31 I know this is what you are looking for, just did this but have a question. Do you want to rank GXT over all the records correct? It is not ranked by date or by another grouping except by the special logic for a category.

     

     

    • bswank31's avatar
      bswank31
      Helper II

      Yes. I want to rank by overall GXT and but I need to have a year, month and site slicer. 

    • bswank31's avatar
      bswank31
      Helper II

      Each Row will have some of the same data like date, site, hole and project. The From and To columns will have some intervals that are the same but will have "Including" in the Category column which those ones should rank right after the interval that it is included in. 

       

    • bswank31's avatar
      bswank31
      Helper II

      This is close! The only thing I see that isn't working correctly is the "Including" isn't following the correct interval it belongs to (If there is an Including with that interval). Is there a way to give the "Including" the same rank as its interval it goes with? 

       

  • bswank31 if you noticed it adds a new column in PQ "GTX for Rank" and it is based on the assumption that "Including" row is next to the row it belongs to, basically it is a way to group otherwise there no logical way to find out "including" belongs to which group. If there is another way to do that then that would be the logic for "GTX for Rank", you have to work with your data and determine what logic works best. 

     

     

    • bswank31's avatar
      bswank31
      Helper II

      I had someone helping me with this a few days ago and this code gave me what I needed until I applied it to my larger data source. Below is the code and output of the code.

      Ranking = 
      VAR current_category = SELECTEDVALUE( Sheet1[Category])
      // Gets the value of the category on the current row.
      VAR gxt = SELECTEDVALUE(Sheet1[GXT])
      // Gets the value of GXT on the current row.
      RETURN
      
      IF( current_category = "Including",
          CALCULATE( RANK.EQ( gxt, Sheet1[GXT], DESC), FILTER( ALLEXCEPT(Sheet1, Sheet1[Date]), Sheet1[Category] = "Including")),
          // Ignore any rows that say "Including".
          CALCULATE( RANK.EQ( gxt, Sheet1[GXT], DESC), FILTER( ALLEXCEPT(Sheet1, Sheet1[Date]), Sheet1[Category] <> "Including")))
          // Using the ALL() function to ensure the whole table is condsidered when evaluating each row.
          // Uning FILTER() to ensure "Including" is being excluded.

      Is there a way to get any of this logic into what you gave me to make it work so the ranking will work how I want?