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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Defraudinho
New Member

Histogram of grouped data

Hello,

I don't know how to resolve this problem.

Imagine I have a list of Zoos and animals living in it (list is thousands of rows long).

AnimalsId of Zoo
Horse1
Elephant1
Horse1
Horse2
Chicken2
Giraffe2
Horse3
Elephant4
Horse5
Elephant5
Elephant6

 

I would like to create a histogram with every "kind" of zoo. In this example:

We have

1 zoo with chickens, horses and giraffes

2 zoos with horses and elephants

2 zoos with elephants

1 zoo with horses

I counted it now, but how to get it in PBI?

I don't care if in the first zoo there is more than one horse

 

Regards

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@Defraudinho,

 

Firstly create a calculate colunm to mark every row:

Flag = 
VAR Type1 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Chicken", "Horse", "Giraffe"})) = 3
VAR Type2 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Horse", "Elephant"})) = 2
VAR Type3 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Elephant"})) = 1
VAR Type4 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Horse"})) = 1
RETURN
SWITCH(TRUE(), Type1, "zoo with chickens, horses and giraffes", Type2, "zoos with horses and elephants", Type3, "zoos with elephants", Type4, "zoo with horses")

1.PNG 

 

Then drag Flag and Id or Zoo to the stack column chart like below:

2.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yuta-msft
Community Support
Community Support

@Defraudinho,

 

Firstly create a calculate colunm to mark every row:

Flag = 
VAR Type1 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Chicken", "Horse", "Giraffe"})) = 3
VAR Type2 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Horse", "Elephant"})) = 2
VAR Type3 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Elephant"})) = 1
VAR Type4 = CALCULATE(DISTINCTCOUNT('Table'[Animals]), FILTER(ALLEXCEPT('Table', 'Table'[Id of Zoo]), 'Table'[Animals] in {"Horse"})) = 1
RETURN
SWITCH(TRUE(), Type1, "zoo with chickens, horses and giraffes", Type2, "zoos with horses and elephants", Type3, "zoos with elephants", Type4, "zoo with horses")

1.PNG 

 

Then drag Flag and Id or Zoo to the stack column chart like below:

2.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.