Create table like Pivot table to do headcount in PowerBI

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have this table

Book1.xlsx
ABCDE
1namegenderdeptagesalary
2mary1fIT2888769
3alex1mSales3659728
4mike1mMarketing3319819
5chin1mHR6989760
6anna1fHR2340182
7sarah1fIT6575338
8danny1mSales2822490
9adam1mIT4669257
10alii1fSales5168221
Sheet1


What I want to create a table that shows dept and headcount for each dept like this

Book1.xlsx
AB
3Row LabelsCount of name
4HR6
5IT7
6Marketing4
7Sales7
8Grand Total24
Sheet2


I did that using Pivot table. Now I want to user Power BI to do that. I can move the dept column to a table place holder but when I move the name to the same table, it listed all names not count of names like what pivot table does, please see the screen shot below below:


How can I create a table like the second one using PowerBI. Thank you very much.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Use the Power Query functionality in PBI. Here is the Mcode

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"gender", type text}, {"dept", type text}, {"age", Int64.Type}, {"salary", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"dept"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"
 
Upvote 0
Use the Power Query functionality in PBI. Here is the Mcode

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"gender", type text}, {"dept", type text}, {"age", Int64.Type}, {"salary", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"dept"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

Thank you very much for your help. Just a question, can it be done without writing M code? I am not familiar with M code yet. Thank you once again.
 
Upvote 0
I did not write Mcode. I used the functionality of Power Query. I selected the column of Data in the Dept Field. I then selected Group By and Had PQ then count the times the Dept appears.

the Mcode is the result of these actions in the U/I
 

Attachments

  • Capture4.JPG
    Capture4.JPG
    36.2 KB · Views: 10
Upvote 0
I did not write Mcode. I used the functionality of Power Query. I selected the column of Data in the Dept Field. I then selected Group By and Had PQ then count the times the Dept appears.

the Mcode is the result of these actions in the U/I
Thank you once again. I appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,223,701
Messages
6,173,920
Members
452,539
Latest member
deeme

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