Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DAX COUNTX giving wrong results

Hi, I am trying to get my code to count the number of dates that have a rank or 5 or anything below 5. I tried to do this with the code below but it doesn't seem to work, could any one help please?
(Heres an image of my dashboard; instead of counting the right number of dates at 5 or under , it counts every date)

Bottom 5 = 

VAR N = 5
RETURN


    COUNTX(

            SUMMARIZE (

                'Date Table','Date Table'[Year and Month],"total"

                ,

                RANKX(all('Date Table'[Year and Month]),

   CALCULATE(SUM(Data[Value])),,ASC,Dense))

          

        ,

        IF([total]<=N,[total],BLANK()))

 

 

  • Anonymous

     

    try like this:

     

    Bottom Nth Value = 
    COUNTROWS(
        FILTER(
            ALL( 'Date Table' ),
            RANKX(
                ALL( 'Date Table' ),
                [TotalValue], , DESC, Dense
            ) < 6
        )
    )
  • Anonymous

     

    For your measure to work you need to remove the filter from  'Year and Month' and from 'Date' such as below:

     

     

    Bottom 5 =
    VAR N = 5
    RETURN
        COUNTX (
            SUMMARIZE (
                'Date Table',
                'Date Table'[Year and Month],
                "total", RANKX (
                    ALL ( 'Date Table'[Year and Month], 'Date Table'[Date] ),
                    CALCULATE (
                        SUM ( Data[Value] )
                    ),
                    ,
                    ASC,
                    DENSE
                )
            ),
            IF (
                [total] <= N,
                [total],
                BLANK ()
            )
        )

     

11 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sure, here are some images of the tables i used 

      • LivioLanzo's avatar
        LivioLanzo
        Icon for Solution Sage rankSolution Sage

        Hi Anonymous,

         

        sorry but I can't work with a snapshot. Are you able to post data which can be copy/pasted?