Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

DAX SQL window function equivalent

Hello,

 

I would like to create a calculated column that returns a total row count per customer, as below.

 

http://imgur.com/WJ2MzJS

 

To do this with SQL, one approach would be to use a window function like:

 

COUNT(*) OVER (PARTITION BY CUSTOMER ORDER BY NULL)

 

Could someone please demonstrate how to achieve the same result using DAX?

 

Thanks!

 

Pbix

  • Anonymous

    Check

     

    Column =
    COUNTAX (
        FILTER ( 'Table', EARLIER ( 'Table'[Customer No.] ) = 'Table'[Customer No.] ),
        'Table'[Product Purchased]
    )

     

     

    A good site for your reference.

3 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    Anonymous

    Check

     

    Column =
    COUNTAX (
        FILTER ( 'Table', EARLIER ( 'Table'[Customer No.] ) = 'Table'[Customer No.] ),
        'Table'[Product Purchased]
    )

     

     

    A good site for your reference.

    • Shmidtk's avatar
      Shmidtk
      New Member

      What if we have unsorted list of Customer No.? They this formula shouldn't work, yes?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Lovely, thanks very much.