cancel
Showing results for
Did you mean:
Frequent Visitor

## Cumulative sum of 'distinct count of months' by Employee Name

Hi Team,

I want to count number of distinct months for each employee and sum them.

As per below example [Snapshot] - My DAX should return value as 7.

i.e. Distinct Sum = Distinct count of months [Month-YY] for 'XYZ' + Distinct count of month [Month-YY] for 'PQR'

= 4+3

= 7

 Table Name - Timesheet Employee_Id Employee Name Date Hours Month-YY 1234 XYZ 01-Nov-18 23 11-18 1234 XYZ 13-Nov-18 12 11-18 1234 XYZ 02-Dec-18 34 12-18 1234 XYZ 12-Dec-18 34 12-18 1234 XYZ 21-Dec-18 34 12-18 1234 XYZ 26-Dec-18 34 12-18 1234 XYZ 02-Jan-19 24 01-19 1234 XYZ 21-Jan-19 24 01-19 1234 XYZ 29-Jan-19 24 01-19 1234 XYZ 02-Feb-19 45 02-19 1234 XYZ 21-Feb-19 45 02-19 2345 PQR 01-Dec-18 34 12-18 2345 PQR 19-Dec-18 34 12-18 2345 PQR 24-Dec-18 34 12-18 2345 PQR 11-Jan-19 32 01-19 2345 PQR 13-Jan-19 32 01-19 2345 PQR 15-Jan-19 32 01-19 2345 PQR 01-Feb-19 55 02-19 2345 PQR 02-Feb-19 55 02-19 2345 PQR 06-Feb-19 55 02-19 Distinct Count of Months by Employee 4+3 = 7 4 Distinct months for 'XYZ' and 3 unique months for 'PQR' = 7

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User

## Re: Cumulative sum of 'distinct count of months' by Employee Name

Hi @Ram_DCT

Try creating a measure like this and placing it in a Card visual, here Table1 is the table you show:

```Measure =
SUMX (
DISTINCT ( Table1[Employee Name] ),
CALCULATE ( DISTINCTCOUNT ( Table1[Month-YY] ) )
)```

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. That allows people trying to help to readily copy the data and run a quick test, plus it increases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

2 REPLIES 2
Highlighted
Super User

## Re: Cumulative sum of 'distinct count of months' by Employee Name

Hi @Ram_DCT

Try creating a measure like this and placing it in a Card visual, here Table1 is the table you show:

```Measure =
SUMX (
DISTINCT ( Table1[Employee Name] ),
CALCULATE ( DISTINCTCOUNT ( Table1[Month-YY] ) )
)```

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. That allows people trying to help to readily copy the data and run a quick test, plus it increases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

Frequent Visitor

## Re: Cumulative sum of 'distinct count of months' by Employee Name

Thank you so much!! I have replaced the table [snapshot to table (Text)].

-Ram