Forum Discussion

mouzzampk's avatar
mouzzampk
Copper Contributor
Nov 15, 2023
Solved

DAX Count with MIN Date

Hi, I have Column A (Date) and Column B (Serial Number)

 

DateSerial
01/02/2019EA12891803
02/02/2019EA12891804
03/02/2019EA12891805
04/02/2019EA12891806
05/02/2019EA12891807
06/02/2019EA12891808
07/02/2019EA12891809
08/02/2019EA12891810
09/02/2019EA12891811
01/01/2019EA12891812
02/01/2019EA12891813
03/01/2019EA12891814
04/01/2019EA12891815
05/01/2019EA12891816
06/01/2019EA12891817
07/01/2019EA12891818
08/01/2019EA12891819
01/01/2019EA12891856

 

I am hoping to get some solution to "Count Serial Number based on MIN date"

 

Expected Outcome

Date            Serial

01/01/2019       2

 

And in Weeks Behind is it possible to show blank field if Oldest Case don't have any date? I am not sure why I am seeing 6,464.

 

  • mouzzampk 

    As variant for

    assuming no other filters

    Oldest Case:=MIN( 'Table'[Date] )
    
    Weeks behind:=INT( (TODAY() - MIN( 'Table'[Date] ) )/7 )
    
    In Queue:=VAR minDate=MIN( 'Table'[Date] )
    RETURN COUNTROWS( FILTER( 'Table', 'Table'[Date] = minDate) )

11 Replies

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    mouzzampk 

    Re. #1 Count Serial Number based on MIN date. Variants with the https://learn.microsoft.com/en-us/dax/countx-function-dax functions:

     

    Count duplicates:

    =COUNTX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] = MINX ( ALL ( 'Table'[Date] ), [Date] )
        ),
        [Serial]
    )

    Count distincts:

    =COUNTX (
        DISTINCT (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Date] = MINX ( ALL ( 'Table'[Date] ), [Date] )
            )
        ),
        [Serial]
    )

     

    • mouzzampk's avatar
      mouzzampk
      Copper Contributor
      Thank you so much for your help. Much appreciated.
      • Lorenzo's avatar
        Lorenzo
        Silver Contributor

        mouzzampk Appreciate your feedback although my suggestions were obviously far too complex 😞

         

        Regards

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    Hi mouzzampk 

     

    #1 Count Serial Number based on MIN date

    If you have duplicates and want to count them:

    =VAR MinOfAllDates =
        CALCULATE (
            MIN ( 'Table'[Date] ),
            ALL ( 'Table'[Serial] )
        )
    RETURN
    CALCULATE(
      COUNT( 'Table'[Serial] ),
      FILTER (
          ALL ( 'Table' ),
          'Table'[Date] = MinOfAllDates
      )
    )

    If you don't want to count potential duplicates: same as above after replacing COUNT with DISTINCTCOUNT

     

    #2 And in Weeks Behind is it possible to show blank field if Oldest Case don't have any date? I am not sure why I am seeing 6,464

    Numeric value of TODAY(): 45,246

    Numeric value of a blank in calc.: 0

    (45,246 - 0) / 7 = 6,463.714286 (rounded up = 6,464)

     

    Difficult to say for sure with your picture only but try the following:

    =IF(
      ISBLANK([Oldest Case]),
      BLANK(),
      DIVIDE( (TODAY() - [Oldest Case]), 7)
    )

    If that doesn't work share your workbook (remove sensitive info.) please

     

    • mouzzampk's avatar
      mouzzampk
      Copper Contributor

      Lorenzo Thank you so much 

       

      Part 2 is fixed but In Queue seem like not outputting correct. I have 2 serial numbers for 24/10/2023 but only one is showing. I have used COUNTX not the top one.

       

       

      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        mouzzampk 

        As variant for

        assuming no other filters

        Oldest Case:=MIN( 'Table'[Date] )
        
        Weeks behind:=INT( (TODAY() - MIN( 'Table'[Date] ) )/7 )
        
        In Queue:=VAR minDate=MIN( 'Table'[Date] )
        RETURN COUNTROWS( FILTER( 'Table', 'Table'[Date] = minDate) )

Resources