cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Count value in different columns

Hi All,

 

I am very new to Power BI and still exploring it.  Suppose we have the following Excel table

 

Name    Country       Comp1    Col2     Col3

A              X                 cs        ps

B              Y                 ps       ip          cs

C              Z                 ip

 

I want to count how many there is a cs ,ps and ip.

And in the visual when i press on CS i want the map representing the Country to highlight the countries that includes the CS 

 

Many thanks

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Count value in different columns

Hi @abukapsoun,

 

If this is the only problem, I would suggest to use a new function "DISTINCTCOUNT".

Measure =
DISTINCTCOUNT ( Table1[Name] )

 

Count value in different columns1.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Because only keeping one row would lead another problem that the connection between "country" and "value" would be broken. (the data in red rectangle belongs to no country.)

 

Count value in different columns2.JPG

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

 

Community Support Team _ Dale
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

3 REPLIES 3
Highlighted
Microsoft
Microsoft

Re: Count value in different columns

Hi @abukapsoun,

 

Firstly, we need to import the data into Power BI from excel.

Secondly, select "Name" and "Country" with "Ctrl" key. Unpivot three columns "Comp1, Col2, Col3".Count value in different columns .jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thirdly, create a measure.

Count = COUNT(Table1[Value])

I attached the file, you can try it yourself. https://1drv.ms/u/s!ArTqPk2pu-BkgQt-qNdTYX9b5zow

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper III
Helper III

Re: Count value in different columns

@v-jiascu-msft

 

Thank you very much Dale.. 

The unpivot trick worked, but created me another problem.

When unpivotting, it will create extra rows but duplication. So if I unpivot Col1 2 3, and I want to count how many person there is in UK, the value would be 3 instead of 1. 

Is there a way I can overcome this problem? Like when unpivotting, only the new created column is filled with values and not the whole row. 

 

Thanks again

Highlighted
Microsoft
Microsoft

Re: Count value in different columns

Hi @abukapsoun,

 

If this is the only problem, I would suggest to use a new function "DISTINCTCOUNT".

Measure =
DISTINCTCOUNT ( Table1[Name] )

 

Count value in different columns1.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Because only keeping one row would lead another problem that the connection between "country" and "value" would be broken. (the data in red rectangle belongs to no country.)

 

Count value in different columns2.JPG

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

 

Community Support Team _ Dale
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

Helpful resources

Announcements
Meet the 2020 Season 2 Power BI Super Users!

Meet the 2020 Season 2 Power BI Super Users!

Find out who's part of the program this season, and welcome the new Super Users.

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Top Solution Authors
Top Kudoed Authors