Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

DAX Trouble with count and Max Date

Hi Everyone!

 

I'm having any difficult with a measure that I need to create.

My scenario is as follow:

 

TABLE1

usu_id_iname_nv
60006Petronila
60027OSCAR
60029Sandra
60030María
60031Carlos
60034Rocio

 

TABLE2

idusu_id_ige_categoria_idfecha_inicio
160006130/08/2016
9812160027130/09/2016
9815860029111/11/2016
9816060030117/11/2016
9816160031118/11/2016
9816260034118/11/2016
9816560006218/11/2016
9816652118/11/2016
9816960030218/11/2016
9817060006121/11/2016
12613223120/02/2017
1261338078220/02/2017
12613460031220/02/2017

 

 

I need a measure that count the actual number of clients by category. As you can see the clients can change between categories do I need to group the client in the most recent category. In this case:

ge_categoria_idClients
14
22



Anyone can help me?
Thanks

  • Anonymous's avatar
    Anonymous
    9 years ago

    Finally I found a solution.


    I have created a column calculated in TABLE1 with the current category of the client.
    It was easier than I expected.


    Thanks for your collaboration.

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

     

    You can try to use below sample if it suitable for your requirement.

     

    Steps:

    1. Filter the not contains records.

    Filtered Table = FILTER(Sheet1,CONTAINS(Sheet2,[usu_id_i],[usu_id_i]))

     

    2. Add a calculated column to analysis the count of date range based on 'category id' group:

    Count = 
    var compare_range = 1
    return
    COUNTX(FILTER('Filtered Table',[ge_categoria_id]=EARLIER([ge_categoria_id])&&[fecha_inicio]>=EARLIER([fecha_inicio])-compare_range&&[fecha_inicio]<=EARLIER([fecha_inicio])+compare_range),[fecha_inicio])

     

     

     

     3. Summary these records.

    Result = SUMMARIZE('Filtered Table',[ge_categoria_id],"Clients",MAX('Filtered Table'[Count]))

     

     

     

    Notice: you can modify the variable 'compare_range' to switch the compare range. Step 1 is an option, you can skip it if you need.

     

    Regards,

    Xiaoxin Sheng

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Anonymous for the answer but I have tried and It didn't work.
      The result of the calculations is wrong.

       

      And I would rather use a measure.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous,

         

        >>The result of the calculations is wrong.

        Can you share some detail information about these?

         

        Regards,

        Xiaoxin Sheng

  • Vvelarde's avatar
    Vvelarde
    Icon for Community Champion rankCommunity Champion

    Anonymous

     

    Hi, what happen with users 52,23,8078 do you want to count them too

     

    Because including it the result will be 6 & 3.

     

    Victor

    Lima - Peru

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Vvelarde,

      Users 52, 23 and 8078 are not included because they aren't in my TABLE1.