Forum Discussion

EPower21's avatar
EPower21
New Member
2 years ago
Solved

DAX Count Keys not working

I want to calculate a distinct count of keys for each user (Pos ID) for each month (KEY). I tried a couple of different approaches, Count 1, Count 2, Count3, but these do not give me the expected va...
  • adudani's avatar
    2 years ago

    hi EPower21 ,

     

    via DAX: 

    key_count = 
    
    
    
    COUNTROWS(
    FILTER('FACT',
    'FACT'[KEY]= EARLIER('FACT'[KEY])
    )
    )

     

     

     

  • Daniel29195's avatar
    2 years ago

    EPower21 

    use this code  :

    Column = 
    
    CALCULATE(
        COUNT('FACT'[KEY]) ,
         ALLEXCEPT('FACT','FACT'[KEY])
    )
    

     

    your first measure should work 

    the issue is that you are counting distinct key,  so it should return 1 not 2 . 

    since the first 2 rows, the keys are equal . 

     

     

    the code i have provided will count ( not distinct ) 

     

    let me know if this helps .

     

     

     

     

    If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

     

     

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi EPower21 ,

     

    You can also create a calculated column.

    _Key Count = 
    CALCULATE(
        COUNT('FACT'[KEY]) ,
        'FACT'[KEY]=EARLIER('FACT'[KEY])
    )

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.