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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Domenick
Helper IV
Helper IV

Matrix - How do I get my measure to divide by week instead of day on drilldown?

I have a matrix visual that shows the percentage of hours that an employee has worked out of their total workable hours for each week. I want to be able to add another field to the column, so that the user can click to drill down and see the projects that contribute to that number. But when I try to do that, the calculation breaks. I would like the percentage shown to be the percentage of hours that employee has worked on that project during that week. But the calculation only divides the number of hours worked into the number of hours available only on the days they worked on the project (not the week). Can someone help me figure out how to have it find the percentage of hours worked out of the whole week?

 

Here is how the data is organized.

There is a labor detail table that shows the number of hours worked:

Domenick_0-1675791614899.png

And an employee calendar table that shows each employees workable hours by day. 

Domenick_1-1675791627095.png

These two tables are related with a concatenated key of Employee+date. The calculation I'm using is simply (SUM(Hours)/Workable Hours). I've tried a few other more complex calculations, but I just can't figure it out.

 

In the example above, the 4 hours that Todd worked on Project 2 on 1/3/23 would appear as 50% (4/8) instead of 5% (4/20).

 

I hope this is enough to give a picture of what I'm working with. Thanks for taking the time to read my headache.

1 ACCEPTED SOLUTION

Can you share the .pbix file so that we can take a look?


I tried like this

sevenhills_0-1675886421457.png

 

2. Data as

sevenhills_1-1675886536108.png

 

sevenhills_2-1675886548167.png

 

3. In the previous post visualization image, Used "Week" from emp calendar table for the left two matrixes and from labor table for the right matrix.

 

 

View solution in original post

6 REPLIES 6
Domenick
Helper IV
Helper IV

The way I solved this was to rewrite my sql query so that it did the math in SQL. 

Glad to hear that it is solved.

Glad to hear that it is solved.

sevenhills
Super User
Super User

Try this if it helps ...

 

1) Add columns to both tables

 

Week = "Week " & WEEKNUM(Table_EmpCalendar[Date],2) 

 

 

2) Add measures

Table: EmpCalendar

 

Sum Emp Calendar Hours = Sum (Table_EmpCalendar[Hours])

 

 

Table: Labor

 

Sum Labor Hours = Sum (Table_Labor[Hours])

 

 

Table: EmpCalendar

 

% by week = 
var _selectWeek = SELECTEDVALUE( Table_EmpCalendar[Week] )
VAR _BASELINE_VALUE = CALCULATE([Sum Emp Calendar Hours], Table_EmpCalendar[Week] = _selectWeek	)
VAR _MEASURE_VALUE = CALCULATE( [Sum Labor Hours], Table_Labor[Week] = _selectWeek )

RETURN  IF ( ISBLANK(_MEASURE_VALUE), BLANK(),  _MEASURE_VALUE/ _BASELINE_VALUE )

 

 

Format the % calc as percentage with 2 decimals

 

Output:

 

sevenhills_1-1675800834011.png

 

 

Thank you so much for this very thoughtful and detailed solution. I followed it to the tee, but it produced the same result as my previous solution 😞 

Can you share the .pbix file so that we can take a look?


I tried like this

sevenhills_0-1675886421457.png

 

2. Data as

sevenhills_1-1675886536108.png

 

sevenhills_2-1675886548167.png

 

3. In the previous post visualization image, Used "Week" from emp calendar table for the left two matrixes and from labor table for the right matrix.

 

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.