cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ram_DCT Frequent Visitor
Frequent Visitor

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

Hi Team,

 

Need your help;

 

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_IdEmployee NameDateHoursMonth-YY
1234XYZ01-Nov-182311-18
1234XYZ13-Nov-181211-18
1234XYZ02-Dec-183412-18
1234XYZ12-Dec-183412-18
1234XYZ21-Dec-183412-18
1234XYZ26-Dec-183412-18
1234XYZ02-Jan-192401-19
1234XYZ21-Jan-192401-19
1234XYZ29-Jan-192401-19
1234XYZ02-Feb-194502-19
1234XYZ21-Feb-194502-19
2345PQR01-Dec-183412-18
2345PQR19-Dec-183412-18
2345PQR24-Dec-183412-18
2345PQR11-Jan-193201-19
2345PQR13-Jan-193201-19
2345PQR15-Jan-193201-19
2345PQR01-Feb-195502-19
2345PQR02-Feb-195502-19
2345PQR06-Feb-195502-19
     
     
Distinct Count of Months by Employee4+3 = 7 
     
4 Distinct months for 'XYZ' and 3 unique months for 'PQR' = 7

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
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
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).

Ram_DCT Frequent Visitor
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