Forum Discussion

HDD328's avatar
HDD328
Frequent Visitor
1 year ago

How to make a calculated column that pulls in values from multiple tables based on two criterias?

I have one table with production times, and 4 others with the nominal times. I am trying to make a calculated column that will bring in the nominal time based on the recipe and machine. I have it working with one table, but the other 3 are having relationship issues which won't allow the column to work correctly. Below is an example of my data along with my current code. Any help would be appreciated!

 

CycleTime= IF(Hourly[Machine] = "M1" && Hourly[Operation] = RELATED(ProdTargetM1[Operation]), RELATED(ProdTargetM1[CycleTime]), IF(Hourly[Machine] = "M2" && Hourly[Operation] = RELATED(ProdTargetM2[Operation]) && Hourly[Recipe] = RELATED(prodtargetm2[RecipeName]), RELATED(ProdTargetM2[CycleTime]), IF(Hourly[Machine] = "M3" && Hourly[Operation] = RELATED(ProdTargetM3[Operation]) && Hourly[Recipe] = RELATED(prodtargetM3[RecipeName]), RELATED(ProdTargetM3[CycleTime]), IF(Hourly[Machine] = "M4" && Hourly[Operation] = RELATED(ProdTargetM4[Operation]) && Hourly[Recipe] = RELATED(prodtargetM4[RecipeName]), RELATED(PapHrProdTargetB02[CycleTime])))))

 

 

2 Replies

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

    • HDD328's avatar
      HDD328
      Frequent Visitor
      Table 1      Table Machine 1 (M1)   Table Machine 2 (M2)  
      OperationStepMachineRecipeProdCycleTime RecipeOperationStepCycleTimeRecipeOperationStepCycleTime
      1S1M11231231.21.43 1231231S11.43 1231231S11.43
      2S2M11231231.341.43 1231232S21.43 1231232S21.43
      3S3M212312321.87 1231233S31.87 1231233S31.87
      4S4M31231231.872.1 1231234S42.1 1231234S42.1
      5S5M41231231.320.99 1231235S50.99 1231235S50.99
      1S1M14564560.651.23 4564561S11.23 4564561S11.23
      2S2M24564560.451.56 4564562S21.56 4564562S21.56
      3S3M24564560.331.15 4564563S31.15 4564563S31.15
      4S4M44564561.563.45 4564564S43.45 4564564S43.45
      5S5M14564561.786.87 4564565S56.87 4564565S56.87
      1S1M3897652.11.33 897651S11.33 897651S11.33
      2S2M3897654.11.45 897652S21.45 897652S21.45
      3S3M4897651.551.77 897653S31.77 897653S31.77
      4S4M1897651.670.87 897654S40.87 897654S40.87
      5S5M2897650.991.54 897655S51.54 897655S51.54

       

      The bold column is whats expected using the code I shared originally. I need the cycle time from the machine tables inserted into table 1 based on the recipe and operation number. PowerBI keeps giving me relationship errors no matter which way I set the relationships up. I believe it has to do with the operation numbers being the same for different recipes, but I am not sure how to get around this. This is to show the actual time taken vs the nominal cycle time from the machine tables.

       

      have attached code again;

       

      CycleTime= IF(Hourly[Machine] = "M1" && Hourly[Operation] = RELATED(ProdTargetM1[Operation]), RELATED(ProdTargetM1[CycleTime]), IF(Hourly[Machine] = "M2" && Hourly[Operation] = RELATED(ProdTargetM2[Operation]) && Hourly[Recipe] = RELATED(prodtargetm2[RecipeName]), RELATED(ProdTargetM2[CycleTime]), IF(Hourly[Machine] = "M3" && Hourly[Operation] = RELATED(ProdTargetM3[Operation]) && Hourly[Recipe] = RELATED(prodtargetM3[RecipeName]), RELATED(ProdTargetM3[CycleTime]), IF(Hourly[Machine] = "M4" && Hourly[Operation] = RELATED(ProdTargetM4[Operation]) && Hourly[Recipe] = RELATED(prodtargetM4[RecipeName]), RELATED(PapHrProdTargetB02[CycleTime])))))