Duplicate rows

Dave2
New Member

Hi,

I need help writing an expression that counts the rows in a table, but excludes rows from the count when there is a duplicate date in the date column. I also need to further constrain the results by the Client ID for the current record, i.e. [_THISROW].[Client ID] = [Client ID]. I can do one or the other, but I havenโ€™t figured out an expression that will do both.

Thanks!

Solved Solved
0 9 683
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

Count of distinct date-column column values in the table table from rows for this client:

COUNT(
  SELECT(
    table[date-column],
    ([_THISROW].[Client ID] = [Client ID]),
    TRUE
  )
)

View solution in original post

9 REPLIES 9

Steve
Platinum 4
Platinum 4

Meaning only count the first row with a given date, or omit any row with a date that occurs more than once?

Correct

Steve
Platinum 4
Platinum 4

Count of distinct date-column column values in the table table from rows for this client:

COUNT(
  SELECT(
    table[date-column],
    ([_THISROW].[Client ID] = [Client ID]),
    TRUE
  )
)

Iโ€™ll give that a shot, thanks!

Looks like that did the trick, thanks again.

Hi Steve,

Follow up question: I need to add another constraint to this expression, which I attempted to do, like this:

COUNT(SELECT(Invoice Detail[VisitDate], AND([_THISROW].[Client ID] = [Client ID], [_THISROW].[User ID]=[User ID], TRUE)))

However now it is no longer omitting rows with a date that occurs more than once. Iโ€™m using this in a virtual column and need a formula that counts only once each date that a user billed to a client (sometimes more than one user bills in a given day, sometimes the same user more than once). Any thoughts on how I can make this work? Thanks!

Your expression on the first line, my suggestion on the second:

COUNT(SELECT(Invoice Detail[VisitDate], AND([_THISROW].[Client ID] = [Client ID], [_THISROW].[User ID]=[User ID], TRUE)))
COUNT(SELECT(Invoice Detail[VisitDate], AND([_THISROW].[Client ID] = [Client ID], [_THISROW].[User ID]=[User ID]), TRUE))

Itโ€™s still counting duplicate dates. Could it be an issue with the way the date is formatted?

If the dates have different formats, sure, that could be an issue.

Top Labels in this Space