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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply

Determining percentages of a whole from another column?

This is sample data for what I'm working on, but essentially what I'm trying to do is group together one column and then find the percentage these groups are of another column. So, in this instance, I'm grouping Rabbit/Deer/Raccoon together as "wildlife" and Dog/Cat/Goldfish together as "domestic pets". I got that far, but now what I'm trying to determine what % of animals in Vermont are wildlife and what percentage are domestic pets. 

 

neutralitycats_0-1664568868067.png

I feel like there's probably a simple solution to this (maybe a DAX measure?), but I just can't figure it out, even after googling for a while. Please help. 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Create a table (Animal Groups) with 2 columns - Animal and Group.  Create a relationship (Many to One and Single) from the Animal column of the Data Table to the Animal column of the Animal groups table.  Create a slicer from the State column of the Data table and select Vermont.  Create a Table visual and drag the Group column from the Animal Groups table.  Write these measures

Total = sum(Data[Count of Animal])

Total of all Groups = calculate([Total],all('animal groups'[Group]))

Ratio = divide([Total],[Total of all Groups])

Hope this helps. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Create a table (Animal Groups) with 2 columns - Animal and Group.  Create a relationship (Many to One and Single) from the Animal column of the Data Table to the Animal column of the Animal groups table.  Create a slicer from the State column of the Data table and select Vermont.  Create a Table visual and drag the Group column from the Animal Groups table.  Write these measures

Total = sum(Data[Count of Animal])

Total of all Groups = calculate([Total],all('animal groups'[Group]))

Ratio = divide([Total],[Total of all Groups])

Hope this helps. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you for this. It would seem like this would work logically, but I'm getting an error that states Column 'Count of Animal' in table 'Data' cannot be found or may not be used in this expression. I have a column Animal in the table Data, so I can't figure out what I'm doing incorrectly.

 

total = sum('Data'[Count of Animal]) 

 

If I do: 

total = sum('Data'[Animal]) it works, but it doesn't give me what I want. 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Sorry, please disregard! I figured out I needed to create a count column.

Shaurya
Memorable Member
Memorable Member

Hi @neutralitycats,

 

Considering the fact that you have already classified the animals into two categories, I am assuming you have a table that looks like this:

 

Screenshot 2022-10-01 022346.jpg

 

The next step would be to group these values to show the count of wildlife and domestic animals by state. You can use the following DAX Formula to do that:

 

Grouped Table = SUMMARIZE(Animals,Animals[State],Animals[Group],"Count",SUM(Animals[Count of Animal]))

 

Screenshot 2022-10-01 022939.jpg

 

Now you can use the EARLIER() function to get the total number of animals in all the states and divide the count of wildlife/domestic by that value to get the perecentage.

 

Percentage = ('Grouped Table'[Count]/SUMX('Grouped Table',IF('Grouped Table'[State]=EARLIER('Grouped Table'[State]),'Grouped Table'[Count],0)))

 

You'll have to format the column as percentage and the result will look like this:

 

Screenshot 2022-10-01 023413.jpg

 

Hope that helps!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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