Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ram_DCT
Helper II
Helper II

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
AlB
Super User
Super User

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).

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

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).

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

 

-Ram

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.