Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

count rows with some conditions

Hi everyone!

I need to count the rows with same idticket, idclient after the first time that they appear. I also have to exclude duplicates so I only have to count once these records. The result is indicated below. so the total in this example should be 10. Can you help, please?
PBI file https://1drv.ms/u/s!AuMLcKZkL7PFgkY3qjc2GJ35giM2?e=aCetar

 



thank you!

17 Replies

  • Hi,

    I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

    It is for creating a measure.

     

     

     

    test 2 fix =
    SUMX (
    'Table',
    CALCULATE (
    SWITCH (
    TRUE (),
    VAR currentidticket =
    MAX ( 'Table'[idticket] )
    VAR currentidclient =
    MAX ( 'Table'[idclient] )
    RETURN
    MINX (
    FILTER (
    ALL ( 'Table' ),
    'Table'[idticket] = currentidticket
    && 'Table'[idclient] = currentidclient
    ),
    'Table'[Date_time]
    )
    = MAX ( 'Table'[Date_time] ), 0,
    COUNTROWS ( 'Table' ) > 1, 1 / COUNTROWS ( 'Table' ),
    1
    )
    )
    )

  • Num occurrences = 
    var currentClient = SELECTEDVALUE( 'Table'[idclient] )
    var currentTicket = SELECTEDVALUE( 'Table'[idticket] )
    var minDate = CALCULATE( MIN('Table'[Date_time]), 'Table'[idclient] = currentClient && 'Table'[idticket] = currentTicket )
    var result = COUNTROWS( SUMMARIZE(
    FILTER( 'Table', 'Table'[idclient] = currentClient && 'Table'[idticket] = currentTicket && 'Table'[Date_time] > minDate ),
    'Table'[idclient], 'Table'[idticket], 'Table'[Date_time]
    ) )
    return result

    using SUMMARIZE across the idclient, idticket and Date_Time columns will filter out any duplicates

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi johnt75 ,

      thank you very much answer but the measure result is blank, did you tested?

      • johnt75's avatar
        johnt75
        Icon for Super User rankSuper User

        Yes, if I put that measure on a table or matrix visual with idticket and idclient on the rows then I get correct values.

        Do you have any other filters applied which could restrict the results ?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Jihwan_Kim , the problem is that my real data has many duplicate dates like the table from the first post, with your formula they are accounted. Do you know how to remove the duplicates? thank  you very much for your help.