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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
mlim0806
Frequent Visitor

Create one table with split columns for each field values

Hi Community, 

 

I'm trying to create a table that displays the count of people within the three categories (gender, ETNY, and travel) within each city. How I achieve this in excel is a trick creating a separate pivot table for each category and simply hiding the repeated columns giving the illusion of one table.

 

The issue with the matrix table in pbi is that it layers on these different field values rather than keeping them separate. 

 

Input data:

CityGenderETNYTravelPerson ID
OrlandoMaleBLYes1
MiamiMaleHIYes2
New YorkFemaleINYes3
DCMaleASYes4
DCFemaleBLNo5
DCFemaleHIYes6
New YorkFemaleINNo7
HoustonFemaleASYes8
DCFemaleBLYes9
New YorkMaleHINo10
HoustonFemaleINNo11
MiamiFemaleASYes12
New YorkMaleBLNo13
OrlandoFemaleHIYes14
OrlandoMaleINYes15
OrlandoFemaleASNo16

 

Desired output:

 GenderETNYTravel 
CityFemaleMaleASBLHIINNoYesTotal number of Person IDs
DC31121 134
Houston2 1  1112
Miami111 1  22
New York22 112314
Orlando221111134
Grand Total106444461016
1 ACCEPTED SOLUTION
ahadkarimi
Solution Specialist
Solution Specialist

Hi @mlim0806, give these a try, and if you run into any issues, let me know.

Measures:

Female Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Gender] = "Female")
Male Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Gender] = "Male")
AS Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "AS")
BL Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "BL")
HI Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "HI")
IN Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "IN")
Yes Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Travel] = "Yes")
No Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Travel] = "No")

use the measures to create a summary table in a matrix visual:
Drag City to Rows.

Drag Female Count, Male Count, AS Count, BL Count, HI Count, IN Count, No Count, Yes Count, to Values in the matrix.
add another measuer:

Total Persons = COUNT('Table'[Person ID])


 

View solution in original post

4 REPLIES 4
ahadkarimi
Solution Specialist
Solution Specialist

Hi @mlim0806, give these a try, and if you run into any issues, let me know.

Measures:

Female Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Gender] = "Female")
Male Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Gender] = "Male")
AS Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "AS")
BL Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "BL")
HI Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "HI")
IN Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[ETNY] = "IN")
Yes Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Travel] = "Yes")
No Count = 
CALCULATE(COUNT('Table'[Person ID]), 'Table'[Travel] = "No")

use the measures to create a summary table in a matrix visual:
Drag City to Rows.

Drag Female Count, Male Count, AS Count, BL Count, HI Count, IN Count, No Count, Yes Count, to Values in the matrix.
add another measuer:

Total Persons = COUNT('Table'[Person ID])


 

Easy solution! Thank you!

My pleasure!

amitchandak
Super User
Super User

@mlim0806 , One of the ways is to unpivot the columns Gender, ETNY, Travel. But that will increase table rows 

 

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements