Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Count duplicates RANK in a matrix visual column without Power Query

Hi

 

I have a very simple visual matrix on a report page with as first column Article names (than can be filtered with a slicer) and a second colum with their Total sales. I made a third column with the ranks on the total sales that works perfectly as expected!

 

However.... i need a fourth column in DAX that for every row shows the number of times a given rank repeats. I'm searching since a week for a solution but i failed.

 

 

Thx a lot for your help

  • SpartaBI's avatar
    SpartaBI
    4 years ago

    Anonymous Why next monday :))
    This is the formula:

     

    # Identical Rank = 
    VAR _tbl = 
        ADDCOLUMNS(
            ALLSELECTED('Table'[Article]),
            "@Rank", RANKX(ALLSELECTED('Table'[Article]), [# Total])
        )
    VAR _current_rank = [Rank]
    VAR _result = 
        COUNTROWS(
            FILTER(
                _tbl,
                [@Rank] = _current_rank
            )
        )
    RETURN
        _result

     


    And these are the other measure I created:

     

    # Total = SUM('Table'[Total])
    
    Rank = RANKX(ALLSELECTED('Table'[Article]), [# Total])

     

     





          

    Showcase Report – Contoso By SpartaBI

12 Replies

  • SpartaBI's avatar
    SpartaBI
    Community Champion

    Anonymous I need more info.
    Can you share a sample file and explain exactly what is the desired result you want to get for that file (with few examples).

    • Anonymous's avatar
      Anonymous
      Not applicable

      I can't download any files at work. Can you share the DAX formula here in plain text on the forum please?

       

      Be sure that if it works i will do a thumbs up next monday 😉

      • SpartaBI's avatar
        SpartaBI
        Community Champion

        Anonymous Why next monday :))
        This is the formula:

         

        # Identical Rank = 
        VAR _tbl = 
            ADDCOLUMNS(
                ALLSELECTED('Table'[Article]),
                "@Rank", RANKX(ALLSELECTED('Table'[Article]), [# Total])
            )
        VAR _current_rank = [Rank]
        VAR _result = 
            COUNTROWS(
                FILTER(
                    _tbl,
                    [@Rank] = _current_rank
                )
            )
        RETURN
            _result

         


        And these are the other measure I created:

         

        # Total = SUM('Table'[Total])
        
        Rank = RANKX(ALLSELECTED('Table'[Article]), [# Total])

         

         





              

        Showcase Report – Contoso By SpartaBI

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Anonymous 
    Here is a sample file with the proposed solution https://www.dropbox.com/t/3ndOIIvOfCavuLwa

     

    # Identical Ranks = 
    VAR CurrentAmount = [Total]
    VAR T1 = ALLSELECTED ( Sales[Article] )
    VAR T2 = ADDCOLUMNS ( T1, "@Total", [Total] )
    VAR T3 = SUMMARIZE ( T2, [@Total], "@Count", DISTINCTCOUNT ( Sales[Article] ) )
    VAR T4 = FILTER ( T3, [@Total] = CurrentAmount )
    RETURN
        SELECTCOLUMNS ( T4, "@@Count", [@Count] )

     

    • tamerj1's avatar
      tamerj1
      Community Champion

      Anonymous 

      Sorry my mistake. Just replace it with [Total] measure I will update the original reply

      • tamerj1's avatar
        tamerj1
        Community Champion

        Anonymous 

        By the way the code in the file is just fine. Just download it

    • Anonymous's avatar
      Anonymous
      Not applicable

      Why did you hardcode one of the value (the 12000) of the matrix in the formula? Does that mean if the the values differ and change over time or that they are more than one duplicate rank your formula won't work anymore?

      • tamerj1's avatar
        tamerj1
        Community Champion

        Anonymous 
        I have updated the screenshot and the code. Actually I have taken the screenshot of a table I just created to track the code but the measure is there in the shared file and the matix is based on it otherwise the results would be wrong.