Pivot Table showing a count AND and % of total

mayday1

Board Regular
Joined
Oct 5, 2007
Messages
241
I have 3 columns (A:C) - header names are PatientID, Reason, Paid

Reason is the reason for the visit, Paid shows if the visit has been paid for. So the data looks like this:

192837 Reason1 Y
459357 Reason2 Y
459379 Reason2 Y
192837 Reason1 Y
459357 Reason2 Y
342873 Reason3 N
345035 Reason2 N
459379 Reason2 Y

How can I do a pivot table that shows the results like this:
PatientID, Total number of visits by this patient, % of that patient's visits that have been paid for

Or is there a non-pivot table way to get this?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
with your example:
is that what you want?

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]PatientID[/td][td=bgcolor:#DDEBF7]Visits[/td][td=bgcolor:#DDEBF7]% of paid[/td][/tr]

[tr=bgcolor:#FFFFFF][td]192837[/td][td]
2​
[/td][td]
33.33%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]342873[/td][td]
1​
[/td][td]
0.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]345035[/td][td]
1​
[/td][td]
0.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]459357[/td][td]
2​
[/td][td]
33.33%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]459379[/td][td]
2​
[/td][td]
33.33%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Grand Total[/td][td=bgcolor:#DDEBF7]
8
[/td][td=bgcolor:#DDEBF7]
100.00%
[/td][/tr]
[/table]


done with PowerQuery & PivotTable

or I missed something
 
Upvote 0
with your example:
is that what you want?

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]PatientID[/td][td=bgcolor:#DDEBF7]Visits[/td][td=bgcolor:#DDEBF7]% of paid[/td][/tr]

[tr=bgcolor:#FFFFFF][td]192837[/td][td]
2​
[/td][td]
33.33%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]342873[/td][td]
1​
[/td][td]
0.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]345035[/td][td]
1​
[/td][td]
0.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]459357[/td][td]
2​
[/td][td]
33.33%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]459379[/td][td]
2​
[/td][td]
33.33%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Grand Total[/td][td=bgcolor:#DDEBF7]
8
[/td][td=bgcolor:#DDEBF7]
100.00%
[/td][/tr]
[/table]


done with PowerQuery & PivotTable

or I missed something



.....almost. Rather than a column showing a patients' percent of the total of paid visits of all patients, I'm looking for the percent of each individual patient's visits that are paid. So 192837 visited twice and paid both times, so for him it's 100%
 
Upvote 0
something like this?

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]PatientID[/td][td=bgcolor:#DDEBF7]Visits[/td][td=bgcolor:#DDEBF7]% of paid[/td][/tr]

[tr=bgcolor:#FFFFFF][td]192837[/td][td]
2​
[/td][td]
100.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]342873[/td][td]
1​
[/td][td]
#DIV/0!
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]345035[/td][td]
1​
[/td][td]
#DIV/0!
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]459357[/td][td]
2​
[/td][td]
100.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]459379[/td][td]
2​
[/td][td]
100.00%​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Grand Total[/td][td=bgcolor:#DDEBF7]
8
[/td][td=bgcolor:#DDEBF7]
100.00%
[/td][/tr]
[/table]
 
Upvote 0
That's exactly it. I can do the pivot table to get the PatientID and Visits columns - that's pivot table 101 easy. But how do I get that 3rd column to be the percent? Not sure on what to click on at all. Not that good with Excel
 
Upvote 0
load your source table to the PowerQuery editor then...
Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PatientID", type text}, {"Reason", type text}, {"Paid", type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Paid] = "Y" then "Y" else null)
in
    #"Added Conditional Column"[/SIZE]
after that you'll get fourth column

then insert PivotTable and use external source (QueryTable)
create three columns as you konw how, and use fourth column as count % of row Total
change the headers as you wish.

edit:
I forgot to say, fourth column of the result will contain error(s) #DIV/0!, so use Conditional Formatting :
format only cells that contain: Errors
and set font color : white

--
you can do that without PQ with formula : IF(Paid=Y,Y,"") and it will be your foruth column then use PivotTable as above with select table or range
 
Last edited:
Upvote 0
Been out a couple days.....

I'm lost already at "load your source table to the PowerQuery editor" I'm in Excel 2013. Where do I find that?





load your source table to the PowerQuery editor then...
Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PatientID", type text}, {"Reason", type text}, {"Paid", type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Paid] = "Y" then "Y" else null)
in
    #"Added Conditional Column"[/SIZE]
after that you'll get fourth column

then insert PivotTable and use external source (QueryTable)
create three columns as you konw how, and use fourth column as count % of row Total
change the headers as you wish.

edit:
I forgot to say, fourth column of the result will contain error(s) #DIV/0!, so use Conditional Formatting :
format only cells that contain: Errors
and set font color : white

--
you can do that without PQ with formula : IF(Paid=Y,Y,"") and it will be your foruth column then use PivotTable as above with select table or range
 
Upvote 0
you can do that without PQ with formula : IF(Paid=Y,Y,"") and it will be your fourth column then use PivotTable as above with select table or range
If you've trouble with PowerQuery there is an option without PowerQuery
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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