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.
Hello All,
I have one column of Projects, two columns of Names, and two columns of Pay in my data set.
Column A = Project Name
Column B = Lead Person
Column C = Support Person
Column D = Lead Pay
Column E = Support Pay
I'd like to write a measure that finds someone's name in both Column B and Column C and sums the appropriate Pay from Columns D & E.
Example
Project ABC Bob Sam $10 $20
Project XYZ Tim Tom $15 $30
Project GEF Sam Tim $50 $75
If I search for Tim, the sum of the pay should be $90 (15 + 75). Additionally, if I filter my table view I'd like to see only the projects that Tim shows up in either Column B or Column C.
Any help is appreciated!
Here's my attempt at solving that problem -
I first created another table with the names of all the staff -
All Staff = DISTINCT(UNION(VALUES('Table (2)'[Lead]), VALUES('Table (2)'[Support])))
This table is disconnected from the original table.
And then I wrote a measure to grab the sum of the pay for each role:
Sum of Pay =
var summaryTable = UNION(
SELECTCOLUMNS('Table (2)', "name", 'Table (2)'[Lead], "pay", 'Table (2)'[Lead Pay]),
SELECTCOLUMNS('Table (2)', "name", 'Table (2)'[Support], "pay", 'Table (2)'[Support Pay])
)
return SUMX(FILTER(summaryTable, [name] = SELECTEDVALUE('All Staff'[Lead])), [pay])
I then used the names from the table I created, and then used the measure to create the results table.
Lastly, for the table filtering requirements, I recommend you take a look at this article that goes more in-depth on slicer filtering: https://apexinsights.net/blog/or-xor-slicing
Hello @vicky_ ,
Thank you for the detailed reply!
I follow most of what you've laid out but have a couple questions.
Thank you again for the help on this!
Hey!
1. Yes, if you already have a list of staff, there's no need to create a new table for that. Just use the name in that table instead of the AllStaff Table I have above. The point of me creating a table with unique names is so that I can grab the pay regardless of if the staff is lead or support.
2. Measures (as opposed to calculated columns) don't depend on the table that they're in, but rather the row and column dimension(s) that are in the visual. So actually, it doesn't matter which table you put the measure in. (Actually, before power BI implemented folders, some people would create an empty table to use as a folder to organise their measures)
3. And again, if you already have a list of names, then you don't need to create a new table for that. Just use the one you already have.
Hope that helps.
Thank you Vicky,
Understood on placement of measures. I've adjusted my work and am still having some issues with the calculations. And it could be how I'm trying to visualize the data.
If I filter my page by a persons name, I would expect the below table to reflect the Total Pay for that individual based on their being lead or support.
So if I use my Name Table to filter this page by Sam, I would want to see the below.
Project Name | Lead Person | Support Person | Lead Pay | Support Pay | Total Pay |
Project ABC | Bob | Sam | 10 | 20 | 20 |
Project XYZ | Sam | Tim | 50 | 75 | 50 |
Right now when I filter using this name I do not get this result. The closest I've gotten is having the Lead Pay shown in Total Pay for both rows.
Regards,
Eric
@vicky_ just following up to see if you have any ideas on this last piece? I'm still unable to get the solution I'm looking for, though I appreciate all your help so far!
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 |
---|---|
100 | |
99 | |
80 | |
77 | |
66 |
User | Count |
---|---|
134 | |
108 | |
104 | |
83 | |
73 |