Michelle Foxen
Michelle Foxen

Reputation: 11

How do I calculate a new column in power bi that sums the values of a column from Table1 then subtracts the sum of groups of rows in Table 2?

I'm new to Power BI and struggling with writing DAX to define a new column for what seems like it should be a simple subtraction exercise. Here's a simulation of my data tables:

Resource Cpty Type 1 Cpty Type 2 Cpty Type 3 Cpty Type 4
Bulldozer 10 50 0 0
Dump Truck 150 150 150 150
Backhoe 25 0 50 50
Project Work Type Resource Usage Hours
Apple Type 1 Bulldozer 8
Apple Type 2 Dump Truck 100
Peach Type 3 Dump Truck 50
Pear Type 4 Backhoe 42
Pear Type 1 Compactor 98
Pear Type 3 Excavator 80
Plum Type 2 Dump Truck 50
Plum Type 1 Dump Truck 25
Pineapple Type 4 Dump Truck 75

I provide a dashboard for each resource by slicing/filtering on the resource. Table 1 has a single row for each resource with multiple capacity type columns that need to be added together to get the [Capacity] for the resource.

Table 2 has the detailed consumption data that shows a project, type of work, the resource and the hours consumed. I want subtotals of usage hours for each group of [resource and work type usage] to show in cards on the dashboard, then I need to show the over/under utilization by taking the summed [Capacity] for the resource from Table 1 and subtracting the sum of each of the [resource and work type usage]for that resource from Table 2.

Using the data example, on a report for the Dump Truck:

I've fiddled with CALCULATE statements and SUM and SUMX but can't get it right.

I was expecting to be able to take a SUM from Table 1 and subtract a SUMX from Table 2, with a slicer/filter applied at the page level. I've tried putting this new column in both Table1 and Table 2, which are joined on [Resource]. The DAX builder doesn't let me choose data from the other table when attempting the calculation.

Help greatly appreciated!

Upvotes: 1

Views: 134

Answers (1)

Ryan
Ryan

Reputation: 2480

in the first table, select the first column and unpivot other column in PQ

enter image description here

enter image description here

  1. create a dim table

dim_table = DISTINCT('Table'[Resource])

  1. create realtionships among three tables enter image description here

  2. then you can use filter to switch the output from different resources

enter image description here

Upvotes: 0

Related Questions