Forum Discussion
Distinct Count from different rows measure
I need help.
I have the below function and the use of the function is to count the number of matching rows from one table if the table record is matching between the 2 tables, and every thing is working fine except for one thing.
Sometimes I will receive 2 rows from my data source for the same sub_name number which will mean that my function will count twice for every record I receive, and I want to let it count only distinct values for the Sub_name column to avoid duplication.
which means for example if I receive the record of Sub_name = 123, twice and the number of matching records is 2 I want it to display 2 instead of 4
My function is as following
SUMX (
ADDCOLUMNS (
TIBCOINCIDENT_UPDATED,
"__DCount",
VAR CurrentSubName = TIBCOINCIDENT_UPDATED[SUB_NAME]
VAR CurrentStatus = TIBCOINCIDENT_UPDATED[STATUS]
VAR CurrentOutageTime = TIBCOINCIDENT_UPDATED[Outage_Time_UAE]
VAR CurrentTime =
NOW ()
RETURN
IF (
CurrentStatus = "Un-Planned Pending"
&& 'TIBCOINCIDENT_UPDATED'[Exceeded] = "No",
CALCULATE (
COUNT ( 'Medical Case'[Acct Src Id] ),
'Medical Case'[Substation] = CurrentSubName
)
) + 0
),
[__DCount]
)Can any one help ?
7 Replies
- some_bihCommunity Champion
Hi Try to replace
COUNT ( 'Medical Case'[Acct Src Id] )with
DISTINCTCOUNT ( 'Medical Case'[Acct Src Id] ),
- ZakhamidoFrequent Visitor
some_bih tried that already but nothing will change, I believe that it will only count the distinct in the 'Medical Case'[Acct Src Id] for every matching condition, for example if I will receive Sub_name = 123 it will count distinct for that particular row and then it will evaluate the second match and count again, so distinct count will not do my requirment in this case as it is counting for every match in the sub_name