Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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.
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.
Solved! Go to Solution.
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.
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.
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.
Sorry, please disregard! I figured out I needed to create a count column.
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:
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]))
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:
Hope that helps!
User | Count |
---|---|
127 | |
108 | |
99 | |
63 | |
62 |
User | Count |
---|---|
136 | |
113 | |
102 | |
71 | |
60 |