Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

SUM Column in Value Exists in Another Table

I have two datasets   Dataset 1 ID Hours Job Type 1 10 Erect 2 10 Dismantle   Dataset 2 ID Estimate Erect Hours Estimate Dismantle Hours 1 15 5 2 10 0   I ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , Anonymous 

    According to your description, you want to get the sum of [Hours] according to the another table the job type hour > 0.

    Here are the steps you can refer to :
    (1)My test data is the same as yours.

    (2)We can create a measure like this:

    Measure = var _t =ADDCOLUMNS( ALLSELECTED('Table 1') , "flag" ,
    var _id = [ID] var _job=[Job Type] var _t = FILTER('Table 2' ,'Table 2'[ID] = _id)   return
    IF(  OR( _job = "Erect" && MAXX(_t, [Estimate Erect Hours])>0 ,_job = "Dismantle" && MAXX(_t, [Estimate Dismantle Hours])>0 )  , 1, 0))
     return
     SUMX(_t ,IF([flag]=1,[Hours],0))

    (3)Then we can get the total:

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly