Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Calculation between three Fact Tables

Hello,

 

I have four tables:

 

fStock (Aggregated at Vendor and Product Level)

- SK_VENDOR

- SK_PRODUCT

- Stock Available

 

SK_VENDORSK_PRODUCTStock Available
12310050000
12310125000
1241103000
1241113500

 

fSales (Aggregated at Vendor and Product Level)

- SK_VENDOR

- SK_PRODUCT

- L7D Items Sold

 

SK_VENDORSK_PRODUCTL7D ITEMS SOLD
123100250
123101300
123102400
1241031000
1241051200

 

fPurchaseOrderItem ( Aggregated at Purchase Order, Vendor and Product Level)

- SK_PURCHASE_ORDER

- SK_VENDOR

- SK_PRODUCT

- Quantity Ordered

 

SK_PURCHASE_ORDERSK_VENDORSK_PRODUCTQuantity Ordered
1123100500
1123101200
1123102300
1123129100

 

fInventory(Aggregated at Vendor and Product Level)

- SK_VENDOR

- SK_PRODUCT

- Units in Inventory

- Cost per Unit

SK_VENDORSK_PRODUCTUnits in InventoryCost per Unit
12310040010
12310130020
12310210030
124100129934

 

 

 

What I need?

- Calculate the Stock Coverage per Days : fStock(Stock Available)/fSales(L7D Items Sold)/7

- Calculate the Stock Value for Products below 30 days of Coverage: fInventory(Units in Inventory)/fInventory(Cost per Unit) for Products where Coverage > 30 Days

- Finally, I need to show the Stock Value in a table Grouped by Purchase Order

 

Example:

SK_PURCHASE_ORDERSK_VENDORQUANTITY ORDEREDStock Value from Supplier > 30 days Coverage
1123100010000
212330010000

 

Is it possible with a calculated measure?

 

Important Notes:

- Coverage should be calculaged upon the combination of Vendor and Product

- One PO can contain multiple Products, but it is always from the same Vendor.

 

Thanks

Carlos

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

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:

vyueyunzhmsft_0-1664948371675.png

(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 :

vyueyunzhmsft_1-1664948419519.png

(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:

vyueyunzhmsft_2-1664948474624.png

 

 

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

 

 

 

View solution in original post

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

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:

vyueyunzhmsft_0-1664948371675.png

(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 :

vyueyunzhmsft_1-1664948419519.png

(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:

vyueyunzhmsft_2-1664948474624.png

 

 

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

 

 

 

Anonymous
Not applicable

Hello

How are you so good on DAX ?

Thanks a lot

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.