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

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.

Reply
AlanBaker
Frequent Visitor

Calculations with Multiple Tables and Multiple RELATED Filters

This probably quite straightforward but I am a new DAX & Power BI User and I have been struggling with the need to create a Measure calculation on a Look up table that references Measures from two different data tables both related back to the Lookup table as many to one.

   Work Orders   
   WorkOrder   
   123   
   456   
   789   
       
       
       
Plans Hours
WorkOrderOperationNoPlan Hours WorkOrderOperationNoActual Hours
12312 45614
12323 45623
789112 78919
       
       
  Work OrderPlansHoursStatus 
  123Plan Hrs = 2Actual Hrs = 0No Action 
  456Plan Hrs = 0Actual Hrs = 7Break-In Work 
  789Plan Hrs = 12Actual Hrs = 9Actioned 
  100Plan Hrs = 0Actual Hrs = 10Break-In Work 
       
       
   Desired Result   
   Count of WorkOrders   
   No Action1  
   Break-In Work2  
   Actioned1  

I want to check if hours were planned in Table Plan and I want to check that Hours were posted in Table Hours and depending on the results I need to determine each Work Order's Status as shown and then Count those results.

I have tried several Measures the latest being and this is to just measure the Break-In Work:

MEASURE: PLANNED_HOURS = SUM(Plans[Plan Hours])        

MEASURE: TIMESHEET_HRS = SUM(Hours[Actual Hours])

WOsNO_BREAK_IN = CALCULATE(

DISTINCTCOUNT(Work Orders [WorkOrder]),

FILTER(Plans, [PLANNED_ HOURS] = 0) && FILTER(Hours, [TIMESHEET_HRS] > 0))

Which gives the error: “A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.”

1 ACCEPTED SOLUTION

Hi @AlanBaker,

 

According to your description above, you should be able to use the formulas below to create three measures and show each of them on the Card visual on the report in your scenario. Smiley Happy

WOsNO_BREAK_IN = 
SUMX (
    'Work Orders',
    IF (
        CALCULATE ( SUM ( Plans[Plan Hours] ) ) = 0
            && CALCULATE ( SUM ( Hours[Actual Hours] ) ) > 0,
        1,
        0
    )
)
WOsNO_NO_ACTION = 
SUMX (
    'Work Orders',
    IF (
        CALCULATE ( SUM ( Plans[Plan Hours] ) ) > 0
            && CALCULATE ( SUM ( Hours[Actual Hours] ) ) = 0,
        1,
        0
    )
)
WOsNO_ACTIONED = 
SUMX (
    'Work Orders',
    IF (
        CALCULATE ( SUM ( Plans[Plan Hours] ) ) > 0
            && CALCULATE ( SUM ( Hours[Actual Hours] ) ) > 0,
        1,
        0
    )
)

r4.PNG

 

Regards

View solution in original post

5 REPLIES 5
CahabaData
Memorable Member
Memorable Member

the layout of your data set is helpful, but it is also confusing as to how your actual data is structured which is key for the correct solution.

 

are Plan Hours and Actual Hours in separate tables - or - do they reside in the same table......  ? 

 

I will guess separate tables.   Because you need a double join of both Work Order & Operation No, which is not possible in PBI, you would create a calculated column that is a merge of both fields/values.  One does this in the Query Editor.   Then join the 2 tables on this new field.

 

Once that's going then creating your next steps becomes easier.

 

But this advice assumes WO+ON is always a unique value.  If there are multiple records with the same WO & ON in the same table then first one is going to need to aggregate them into a single record.

www.CahabaData.com

Many thanks for the quick response!

They are indeed separate tables Work Order is the lookup and Hours and Plans are separate tables linked up to it Work Order many to one.

 

I have tried calculated columns in the Work Order table and I did get the desired results that enabled me to calculate a third column that was equal to either:

Break-In

Actioned

No Action

 

But the problem is when I utilse the calculated columns in the Power BI Pie Chart the result is NOT influenced by the report filters for say filtering by trade (craft) or department instead I get the result of the complete table which as I understand the training material is what I should expect?

I'm afraid the confusion in the diagram is due to a couple of things I will clarify the Hours Table Header has moved to the left.

 

The results of the calculations that I require are in the lower half of the spreadsheet.

 

There is an error in the calculation of Workorder 123 Result which should be 5 not 2

 

Please see ammended table below:

 

       
   Table Work Orders(One)  
   WorkOrder   
   123   
   456   
   789   
       
 Table Plans(Many)  Table Hours(Many)
WorkOrderOperationNoPlan Hours WorkOrderOperationNoActual Hours
12312 45614
12323 45623
789112 78919
       
       
  RESULTSSUMMARIES BELOW  
       
  Work OrderPlansHoursCalculated Status 
  123Plan Hrs = 5Actual Hrs = 0No Action 
  456Plan Hrs = 0Actual Hrs = 7Break-In Work 
  789Plan Hrs = 12Actual Hrs = 9Actioned 
  100Plan Hrs = 0Actual Hrs = 10Break-In Work 
       
       
   FINAL Desired Result   
   Count of WorkOrders   
   No Action1  
   Break-In Work2  
   Actioned1  

Hi @AlanBaker,

 

According to your description above, you should be able to use the formulas below to create three measures and show each of them on the Card visual on the report in your scenario. Smiley Happy

WOsNO_BREAK_IN = 
SUMX (
    'Work Orders',
    IF (
        CALCULATE ( SUM ( Plans[Plan Hours] ) ) = 0
            && CALCULATE ( SUM ( Hours[Actual Hours] ) ) > 0,
        1,
        0
    )
)
WOsNO_NO_ACTION = 
SUMX (
    'Work Orders',
    IF (
        CALCULATE ( SUM ( Plans[Plan Hours] ) ) > 0
            && CALCULATE ( SUM ( Hours[Actual Hours] ) ) = 0,
        1,
        0
    )
)
WOsNO_ACTIONED = 
SUMX (
    'Work Orders',
    IF (
        CALCULATE ( SUM ( Plans[Plan Hours] ) ) > 0
            && CALCULATE ( SUM ( Hours[Actual Hours] ) ) > 0,
        1,
        0
    )
)

r4.PNG

 

Regards

Many thanks, a little more knowledge is cemented into place!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.