Forum Discussion
count rows with some conditions
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
Hi johnt75 ,
thank you very much answer but the measure result is blank, did you tested?
- johnt754 years ago
Super 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 ?
- Anonymous4 years agoNot applicable
No, I don't have any filters that restrict the results. I need this measure on a card but the result of that measure is blank. In the matrix the total that you see is blank and for that reason on the card is blank too.
In the future, I will only have a filter that is in the date table "interval" to see which tickets belong to each interval.
Your solution seems so elegant and nice but for the moment doesn't work for this purpose :/.- johnt754 years ago
Super User
I understand, you want the overall total not broken down by client / ticket.
Num occurrences = SUMX( ADDCOLUMNS( SUMMARIZE( 'Table', 'Table'[idclient], 'Table'[idticket], 'Table'[Date_time] ),
"@value",
var currentClient = CALCULATE( SELECTEDVALUE( 'Table'[idclient] ) )
var currentTicket = CALCULATE( 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
), [@value])should give you what you're after