Forum Discussion
Create a Matrix from two tables that includes Measures and a "Target" column
Hello!
I need to create a matrix in BI where the row headers are the department, the columns are the numerical representations of the months of the year (ie., Jan = 1, Feb = 2, etc.), but the last column needs to say "Target". The values for the months are a measure/calculation whereas the Target column would show the target value from a separate table. Here's a representation of what the first table would show:
Table 1:
| Dept | Month | Year | Time Worked | Hours Billed |
| A | 1 | 2023 | 8 | 7 |
| A | 2 | 2023 | 9 | 8 |
| B | 1 | 2023 | 10 | 6 |
| B | 2 | 2023 | 9 | 4 |
Table 2:
| Dept | Year | Plan Target |
| A | 2023 Plan | 60% |
| B | 2023 Plan | 80% |
Final Result would look something like this:
| Year | 2023 | ||||||||||||
| Dept | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Plan Target |
| A | 88% | 89% | 75% | 65% | 85% | 95% | 65% | 48% | 35% | 87% | 88% | 95% | 60% |
| B | 60% | 44% | 50% | 64% | 56% | 45% | 87% | 24% | 65% | 86% | 57% | 79% | 80% |
I have no problems creating a measure for the values of the table (from Table 1: Hours Billed / Time Worked) but I don't know how to pull in that target number from Table 2 and also show the column header as "Plan Target".
Any assistance would be greatly appreciated!
Hi JLambs20
Would something like the following work?
In Power Query:
- Create a Period custom column (=Text.From([Month]) & "/1/" & Text.From([Year])) (Your format might be different.)
- Change type to date
- Remove [Year] and [Month] columns
- I also renamed the queries to ‘Fact-Table1’ and ‘Dim-Table2’.
Exit Power QueryI created a simple DAX Date table and related it to ‘Fact-Table1’. Also, relate ‘Fact-Table1’ and ‘Dim-Table2’ on [Dept].
Create the following measure and format as Percentage.
Pct = IF( HASONEVALUE( 'Date'[MonthNo] ), AVERAGEx( 'Fact-Table1', DIVIDE( [Hours Billed], [Time Worked] ) ), AVERAGE( 'Dim-Table2'[Plan Target] ) )Create a matrix and populate as follows:
Rows: ‘Dim-Table2’[Dept]
Columns: ‘Date’[MonthNo]
Values: [Pct]In the Format pane under Column Subtotals, change the Subtotal Label to “Plan Target”.
Let me know how it goes.
1 Reply
- gmsamborn
Super User
Hi JLambs20
Would something like the following work?
In Power Query:
- Create a Period custom column (=Text.From([Month]) & "/1/" & Text.From([Year])) (Your format might be different.)
- Change type to date
- Remove [Year] and [Month] columns
- I also renamed the queries to ‘Fact-Table1’ and ‘Dim-Table2’.
Exit Power QueryI created a simple DAX Date table and related it to ‘Fact-Table1’. Also, relate ‘Fact-Table1’ and ‘Dim-Table2’ on [Dept].
Create the following measure and format as Percentage.
Pct = IF( HASONEVALUE( 'Date'[MonthNo] ), AVERAGEx( 'Fact-Table1', DIVIDE( [Hours Billed], [Time Worked] ) ), AVERAGE( 'Dim-Table2'[Plan Target] ) )Create a matrix and populate as follows:
Rows: ‘Dim-Table2’[Dept]
Columns: ‘Date’[MonthNo]
Values: [Pct]In the Format pane under Column Subtotals, change the Subtotal Label to “Plan Target”.
Let me know how it goes.