Forum Discussion

duisinvalid's avatar
duisinvalid
Regular Visitor
1 year ago
Solved

Creating a Measure Between Two Unrelated Tables

I have an issue in such that I want to calculate the total hours that each of machine type is running across all factories. I have snippet a small dataset of the two tables that I have been working ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi duisinvalid ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create measures.

    Measure = 
    var _all_day=COUNTROWS(ALLSELECTED('Date'[Date]))
    var _day_a=_all_day-COUNTROWS(FILTER(ALL('Table b'),[Day_Unopen]<=MAX('Date'[Date]) && [Day_Unopen]>=MIN('Date'[Date]) && [Factory]="A"))
    var _day_b=_all_day-COUNTROWS(FILTER(ALL('Table b'),[Day_Unopen]<=MAX('Date'[Date]) && [Day_Unopen]>=MIN('Date'[Date]) && [Factory]="B"))
    var _pop_a=CALCULATE(SUM('Table a'[Population]),FILTER(ALL('Table a'),[Machine_Type]=MAX('Table a'[Machine_Type]) && [Factory]="A"))
    var _pop_b=CALCULATE(SUM('Table a'[Population]),FILTER(ALL('Table a'),[Machine_Type]=MAX('Table a'[Machine_Type]) && [Factory]="B"))
    RETURN _day_a*_pop_a*24 + _day_b*_pop_b*24
    Measure 2 = SUMX(VALUES('Table a'[Machine_Type]),[Measure])

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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