Averaging Distinct Counts in a Pivot Table

%3CLINGO-SUB%20id%3D%22lingo-sub-1588316%22%20slang%3D%22en-US%22%3ERe%3A%20Averaging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1588316%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F530974%22%20target%3D%22_blank%22%3E%40umasirhc%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecan%20you%20please%20upload%20an%20example%20file%20explaining%20on%20the%20file%20what%20you%20need%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1588010%22%20slang%3D%22en-US%22%3EAveraging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1588010%22%20slang%3D%22en-US%22%3E%3CP%3EOK%2C%20I've%20created%20a%20Pivot%20Table%20that%20pulls%20the%20distinct%20count%20of%20patient%20identifiers%20per%20date%20in%20one%20column%20by%20the%20date%20in%20the%20rows%20from%20a%20query.%26nbsp%3B%20I'm%20trying%20to%20get%20a%20calculation%20of%20the%20average%20daily%20number%20of%20distinct%20patient%20identifiers%20but%20I'm%20struggling.%26nbsp%3B%20I've%20added%20the%20data%20to%20the%20Data%20Model%20and%20tried%20to%20play%20around%20with%20measures%2C%20but%20just%20can't%20get%20it%20to%20work.%26nbsp%3B%20Any%20ideas%3F%26nbsp%3B%20How%20do%20you%20get%20Excel%20to%20calculate%20a%20distinct%20count%20for%20each%20day%20and%20then%20average%20those%20distinct%20counts%20by%20the%20number%20of%20dates%20in%20the%20Pivot%20Table%3F%26nbsp%3B%20Sorry%20I%20can't%20provide%20a%20test%20sheet%20with%20this%20question.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1588010%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1590028%22%20slang%3D%22en-US%22%3ERe%3A%20Averaging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1590028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F746148%22%20target%3D%22_blank%22%3E%40ramizassaf%3C%2FA%3EWell%20I%20thought%20I%20responded%20earlier%20but%20it%20didn't%20go%20through.%26nbsp%3B%20I%20added%20an%20example%20sheet%20to%20the%20original%20post.%26nbsp%3B%20I%20used%20a%20pivot%20table%20and%20the%20data%20model%20to%20get%20the%20distinct%20count%20by%20patient%20ID%2C%20but%20then%20I%20want%20to%20get%20the%20daily%20average%20of%20distinct%20patient%20IDs.%26nbsp%3B%20I%20know%20I%20can%20just%20plug%20the%20grand%20total%20cells%20into%20an%20average%20formula%20but%20I'd%20like%20it%20to%20be%20a%20little%20more%20automated%20since%20the%20data%20table%20will%20just%20continue%20to%20grow.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1590043%22%20slang%3D%22en-US%22%3ERe%3A%20Averaging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1590043%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F530974%22%20target%3D%22_blank%22%3E%40umasirhc%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Euse%20unique%20and%20countif%3C%2FP%3E%3CP%3Eit%20should%20work%26nbsp%3B%3C%2FP%3E%3CP%3Ehere%20you%20go%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1590966%22%20slang%3D%22en-US%22%3ERe%3A%20Averaging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1590966%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F530974%22%20target%3D%22_blank%22%3E%40umasirhc%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20add%20measure%20as%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powerquery%22%3E%3CCODE%3EDaily%20Average%20of%20Unique%20Patients%3A%3DAVERAGEX(%0A%20%20%20SUMMARIZE(%0A%20%20%20%20%20%20%20%20Range%2C%0A%20%20%20%20%20%20%20%20Range%5BDATE%5D%2C%0A%20%20%20%20%20%20%20%20%20%22Daily%20Unique%22%2C%20DISTINCTCOUNT(Range%5BPatient%20ID%5D)%0A%20%20%20%20%20)%2C%0A%5BDaily%20Unique%5D)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EResult%20is%20like%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20523px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F212630i1265636D47EFAB53%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1593434%22%20slang%3D%22en-US%22%3ERe%3A%20Averaging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1593434%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3EThanks!%20This%20worked%20perfectly!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1599748%22%20slang%3D%22en-US%22%3ERe%3A%20Averaging%20Distinct%20Counts%20in%20a%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1599748%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F530974%22%20target%3D%22_blank%22%3E%40umasirhc%3C%2FA%3E%26nbsp%3B%2C%20you%20are%20welcome%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

OK, I've created a Pivot Table that pulls the distinct count of patient identifiers per date in one column by the date in the rows from a query.  I'm trying to get a calculation of the average daily number of distinct patient identifiers but I'm struggling.  I've added the data to the Data Model and tried to play around with measures, but just can't get it to work.  Any ideas?  How do you get Excel to calculate a distinct count for each day and then average those distinct counts by the number of dates in the Pivot Table?  Sorry I can't provide a test sheet with this question.

 

6 Replies
Highlighted

@umasirhc 

can you please upload an example file explaining on the file what you need?

Highlighted

@Ramiz_AssafWell I thought I responded earlier but it didn't go through.  I added an example sheet to the original post.  I used a pivot table and the data model to get the distinct count by patient ID, but then I want to get the daily average of distinct patient IDs.  I know I can just plug the grand total cells into an average formula but I'd like it to be a little more automated since the data table will just continue to grow.

Highlighted

@umasirhc 

 

use unique and countif

it should work 

here you go

Highlighted

@umasirhc 

You may add measure as

Daily Average of Unique Patients:=AVERAGEX(
   SUMMARIZE(
        Range,
        Range[DATE],
         "Daily Unique", DISTINCTCOUNT(Range[Patient ID])
     ),
[Daily Unique])

Result is like

image.png

Highlighted

@Sergei BaklanThanks! This worked perfectly!

Highlighted

@umasirhc , you are welcome