Count of Distinct Values from a column

Mavericks334

Active Member
Joined
Jan 26, 2011
Messages
280
Hi,

I have a table that has the below data in columns
[TABLE="width: 202"]
<COLGROUP><COL style="WIDTH: 120pt; mso-width-source: userset; mso-width-alt: 5851" width=160><COL style="WIDTH: 82pt; mso-width-source: userset; mso-width-alt: 3986" width=109><TBODY>[TR]
[TD="class: xl66, width: 160, bgcolor: transparent"]Preparer[/TD]
[TD="class: xl67, width: 109, bgcolor: #8db4e2"]Completed Date[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: transparent"]Sobkowiak, Bartosz[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:03 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Sobkowiak, Bartosz[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:03 AM[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: transparent"]Sobkowiak, Bartosz[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:03 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Rozmarynowska, Joanna[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: transparent"]Rozmarynowska, Joanna[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Rozmarynowska, Joanna[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: transparent"]Wegielska, Anna[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Rozmarynowska, Joanna[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #dce6f1"]Wegielska, Anna[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Zalewska, Malgorzata[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:04 AM[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #dce6f1"]Zalewska, Malgorzata[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:05 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Dobruchowska, Edyta[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:22 AM[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #dce6f1"]Dobruchowska, Edyta[/TD]
[TD="class: xl69, bgcolor: #dce6f1, align: right"]8/1/12 1:22 AM[/TD]
[/TR]
[TR]
[TD="class: xl70, bgcolor: transparent"]Wlodarczak, Malgorzata[/TD]
[TD="class: xl71, bgcolor: transparent, align: right"]8/1/12 1:22 AM[/TD]
[/TR]
</TBODY>[/TABLE]

I need to caculate the unique no.of days the person has worked.

I created a measure =COUNTROWS(DISTINCT('SharePoint Data'[Completed Date])), the problem with this is that it counts all the days, since there is a time stamp. how do i create a measure so that it would only count the data.
 
see if this works

Excel 2003
ABCDEF
1NameCompleted DateNameCounts
2Sobkowiak, Bartosz8/1/2012 1:03Sobkowiak, Bartosz2
3Sobkowiak, Bartosz8/2/2012 1:03Rozmarynowska, Joanna1
4Sobkowiak, Bartosz8/1/2012 1:03Wegielska, Anna1
5Rozmarynowska, Joanna8/1/2012 1:04Zalewska, Malgorzata2
6Rozmarynowska, Joanna8/1/2012 1:04Dobruchowska, Edyta1
7Rozmarynowska, Joanna8/1/2012 1:04Wlodarczak, Malgorzata1
8Wegielska, Anna8/1/2012 1:04
9Rozmarynowska, Joanna8/1/2012 1:04
10Wegielska, Anna8/1/2012 1:04
11Zalewska, Malgorzata8/1/2012 1:04
12Zalewska, Malgorzata8/1/2012 1:05
13Dobruchowska, Edyta8/1/2012 1:22
14Dobruchowska, Edyta8/1/2012 1:22
15Wlodarczak, Malgorzata8/1/2012 1:22
Sheet1
Cell Formulas
RangeFormula
F2{=SUM(IF(FREQUENCY(IF(A$2:A$21=E2,MATCH(B$2:B$21,B$2:B$21,0)),ROW(B$2:B$21)-ROW(B$2)+1),1))}
Press CTRL+SHIFT+ENTER to enter array formulas.


copy the formula down
 
Upvote 0
Thanks for the abobe formula, it would work fine in excel, however i require a formula to work in powerpivot.
 
Upvote 0
I believe if you create another column to calculate your date field into a time intelligent function you can use your formula.
What you want is just the date so look at this page to get rid of the time value in your column so the DISTINCT will look at that level and ignore time.
DATE Function
Make your formula refer to the new calculated field.
 
Last edited:
Upvote 0
Hi,

I have created another field and used INt(Date Column) to convert the date, the problem is i am increasing the size of my file, i need to creature a measure to do the same, so the file size does not increase much.
 
Upvote 0
It is probably a best practise to actually split your date time columns in date and time.

The easiest way - in Excel and Powerpivot - to get the date from a datetime is to truncate it using the INT function.
 
Upvote 0
I have already used that, trying to see whether i could avoid creating an addtional column, by creating a measure, which would reduce the size of my sheet.
 
Upvote 0
In fact, according to the author of this book, splitting your date time value in two columns may lead to saving memory consumption, due to the way PowerPivot is working.

When I say that I mean importing two columns in PowerPivot instead of one, not adding two additional columns on top of the combined datetime column.

Also, if you create a date table, then you will need the date (without time) to build a relationship.
 
Upvote 0
The problem that i am facing is i am unable to get the max unique count of days, because the date is one column and i need to calculate the max dates a person has worked, because the person could i be in column A or cloumn B
 
Upvote 0
hi,

I don't have Power Pivot and am unfamiliar with it. Maybe though it helps to know a solution for earlier versions of Excel? If I understand the question correctly, this SQL does what you want. I tested in Excel 2003. I'm guessing this can be used in Power Pivot. HTH

Code:
SELECT YourNameField, COUNT(*) AS [YourCount]
FROM 
(SELECT DISTINCT YourNameField, INT(YourDateField)
FROM your_table_name)
GROUP BY YourNameField
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top