Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I am trying to calculate the percentage of the total for an unpivot column that will be coming along with a slicer. I am pretty new to power bi so this may possibly be a pretty easy one. However, I am having trouble trying to make it work. Any help would be appreciated.
I have a sample table,
EID | Gender | Company | Bilingual |
456 | Male | A | Can Speak two languages |
123 | Female | A | Can speak one language |
097 | Male | B | Can Speak two languages |
678 | Female | B | Can Speak two languages |
345 | Male | B | Can speak one language |
234 | Male | A | Can speak one language |
098 | Female | A | Can Speak two languages |
786 | Female | A | Can speak one language |
546 | Female | B | Can Speak two languages |
874 | Female | B | Can Speak two languages |
012 | Male | A | Can Speak two languages |
023 | Male | A | Can speak one language |
056 | Male | B | Can speak one language |
604 | Female | B | Can Speak two languages |
I did an unpivot on the columns gender and bilingual,
EID | Company | Unpivot |
456 | A | Male |
456 | A | Can Speak two languages |
123 | A | Female |
123 | A | Can speak one language |
097 | B | Male |
097 | B | Can Speak two languages |
678 | B | Female |
678 | B | Can Speak two languages |
345 | B | Male |
345 | B | Can speak one language |
234 | A | Male |
234 | A | Can speak one language |
098 | A | Female |
098 | A | Can Speak two languages |
786 | A | Female |
786 | A | Can speak one language |
546 | B | Female |
546 | B | Can Speak two languages |
874 | B | Female |
874 | B | Can Speak two languages |
012 | A | Male |
012 | A | Can Speak two languages |
023 | A | Male |
023 | A | Can speak one language |
056 | B | Male |
056 | B | Can speak one language |
604 | B | Female |
604 | B | Can Speak two languages |
Afterward, I created a table that looks like this,
As you can see, my "%" measure is incorrect when I select it for just one company. However, when I select both the company, it shows correctly.
My code for the measure is the following:
@supergallager34 - As I suspected, not unpivoting makes things much easier. You can use a matrix and "Show as percentage of grand total". See if the attached PBIX is acceptable. Below sig. Has all of the information and numbers should be accurate. Table (7) and Page 7.
Gregg,
I have taken your suggestion and did the unpivot which seemed to make it easier since I would need to create calculations with the percentage of grand total.
However, my calculation also consists of a date slicer. And the table originally contains enter and leave dates. I have inactive relationships with the enter and leave dates with a date table. And my codes then are,
% = CALCULATE(CALCULATE(DIVIDE(DISTINCTCOUNT('Table'[Employee ID]),CALCULATE(DISTINCTCOUNT('Table'[Employee ID]),ALLSELECTED())),
FILTER(VALUES('Table'[Enter_Date]),'Table'[Enter_Date] <= MAX('Date'[Dates])),
FILTER(VALUES('Table'[Leave_Date]),'Table'[Leave_Date] >= MIN('Date'[Dates]))).
When I use this formula, my percentage of grand totals seems to show wrong percentages.
@supergallager34 - Should be and I will have to take a closer look but off the top of my head, it bugs me that you unpivoted those columns, that would not have been my first choice.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
43 | |
23 | |
21 | |
15 | |
15 |
User | Count |
---|---|
45 | |
31 | |
30 | |
18 | |
17 |