Forum Discussion

andresp_g's avatar
andresp_g
New Member
6 years ago
Solved

join tables vs relation between tables

Hi everyone,  let me explain what I'm trying to achieve. I have a table with my inventory information like this   Date Product Color Value 1 1 1 500 1 1 2 300 1 2 1 400 ...
  • d_gosbell's avatar
    d_gosbell
    6 years ago

    Xue's formula has a flaw in it at the total level, because it is filtering 'Table' on MAX(Table1[ProductID] ) at the grand total level the max is equal to 2. So the SUM(Value) returns 650 and the SUM(Table1[Allocation]) is not filtered at all as the filter is applied to the other table, so it returns the sum of all Allocations which is 200%. So 650 x 200% = 1300

     

    For logic like this you would be better to use a SUMX pattern to loop over one of the tables row by row. (I'm also filtering on both date and product as per your original requirement)

    Allocated Value = SUMX( 'Table 1', 
      Var _date = 'Table 1'[Date]
      var _product = 'Table 1'[Product]
    return 'Table 1'[Allocation] * CALCULATE( SUM('Table'[Value]), 'Table'[Date] = _date, 'Table'[Product] = _product) )