Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Calculation between three Fact Tables

Hello,   I have four tables:   fStock (Aggregated at Vendor and Product Level) - SK_VENDOR - SK_PRODUCT - Stock Available   SK_VENDOR SK_PRODUCT Stock Available 123 100 50000 12...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , Anonymous 

    Here are my test you can refer to :

    (1)For your first question. We can create a calculated column in 'fStock' Table :

    Stock Coverage per Days = var _current_vendor = 'fStock'[SK_VENDOR]
    var _current_product = 'fStock'[SK_PRODUCT]
    var _t2= FILTER('fSales','fSales'[SK_VENDOR]=_current_vendor && 'fSales'[SK_PRODUCT] = _current_product)
    return 
    DIVIDE( 'fStock'[Stock Available] , SUMX(_t2,[L7D ITEMS SOLD]) * 7 )

     The result is as follows:

    (2)For your second question . We can create a measure :

    Measure = var _current_vendor = SELECTEDVALUE('fInventory'[SK_VENDOR])
    var _current_product = SELECTEDVALUE('fInventory'[SK_PRODUCT])
    var _ts =MAXX(FILTER(ALLSELECTED('fStock') , 'fStock'[SK_VENDOR]+_current_vendor  && 'fStock'[SK_PRODUCT]=_current_product),[Stock Coverage per Days])
    return 
    IF( _ts > 30  , DIVIDE(SUM('fInventory'[Units in Inventory]) , SUM('fInventory'[Cost per Unit]) ,BLANK()))

    The result is as follows :

    (3)For you last question . We can create a table:

    Table = var _greate30 =DISTINCT( SELECTCOLUMNS( FILTER('fStock', 'fStock'[Stock Coverage per Days] >30 ) , "VENDOR" , [SK_VENDOR]))
    var  _po_t =FILTER('fPurchaseOrderItem' , 'fPurchaseOrderItem'[SK_VENDOR] in  _greate30)
    return 
    SUMMARIZE(_po_t , [SK_PURCHASE_ORDER] , [SK_VENDOR] , "QUANTITY ORDERED" ,SUM('fPurchaseOrderItem'[Quantity Ordered]))

    And then we can create a calculated column :

    Stock Value from Supplier > 30 days Coverage = var _current_vendor = 'Table'[SK_VENDOR] 
    var _t =SUMX( FILTER( 'fStock' , 'fStock'[Stock Coverage per Days]> 30 &&  'fStock'[SK_VENDOR]=_current_vendor ) , [Stock Available])
    return _t

    The result is as follows:

     

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

     

    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