DAX Expressions new
DAX Expressions new
DAX Expressions new
net
sqldb-bi
COMMENTS IN DAX
Just select line(s) of code you want to comment.
Press Crtl + KC to comment those lines.
Press Ctrl + KU to uncomment commented lines.
****************************************************** Set Context
**********************
Shipped_QTY cc =
VAR line_id = newIntrShip[Order_Line_ID] -- setting context
VAR shipped_till_date= CALCULATE(
SUM(newIntrShip[RSL_Shipped_QTY]),
ALL(newIntrShip), -- setting
context
newIntrShip[Order_Line_Number]=line_id, -- setting
context
newIntrShip[Shipment_Status] in{"PARTIALLY RECEIVED",
"FULLY RECEIVED"}
)
RETURN
shipped_till_date
ECCN Discrepancy =
var a = RELATED('Item_BasicInfo'[DFF ECCN])
var b = 'Item_Orginfo'[Org ECCN]
var c=RELATED(Organization[Organization Code])
var d = SWITCH(TRUE(),
(a=b)||(a<>BLANK() && b=BLANK())||(a=BLANK() && b=BLANK()),"NO",
(a=BLANK() && b<>BLANK()),"YES",
(c IN {"135","191","415"} ) && (a<>b),"NO","YES")
return d
ECCN Discrepancy =
var a = RELATED(Item_BasicInfo[DFF ECCN]
var b = Item_Orginfo[Org ECCN]
var c = if(Item_Orginfo[Organization ID]=6782,(if(a<>b,"YES"))
return c
ECCN Discrepancy =
IF(not(
Item_Orginfo[Organization ID] IN{6782,5353,66782} &&
Item_Orginfo[MST ECCN]<>Item_Orginfo[Org ECCN]), "NO",
IF((
Item_Orginfo[Organization ID] IN{6782,5353,66782} &&
Item_Orginfo[MST ECCN]<>Item_Orginfo[Org ECCN]),"YES"))
ECCN Discrepancy =
IF(not( Item_Orginfo[Organization ID] IN{6782,5353,66782} && Item_Orginfo[MST
ECCN]<>Item_Orginfo[Org ECCN]),"YES","NO")
//IF(( Item_Orginfo[Organization ID] IN{6782,5353,66782} && Item_Orginfo[MST
ECCN]<>Item_Orginfo[Org ECCN]),"NO")
COO Discrepancy = Switch(True(),
Item_Orginfo[MST COO]=BLANK() && Item_Orginfo[ORG COO]<>BLANK()||
Item_Orginfo[MST COO]<>Item_Orginfo[ORG COO],
"YES","NO")
Assigned to Position =
var cntPosition = CALCULATE(COUNTROWS(Control_Functions))
RETURN
IF(cntPosition>0,"Yes","No")
PO Amount Bucket =
var a = 'Purchase Order Bucket'[USD Amount]
return b
Aging =
if(TODAY()-PurchaseOrder[PO Creation Date]< 120,"00-04 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]< 180,"04-06 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]< 270,"07-09 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]< 365,"10-12 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]<540,"1.0-1.5 Years",
if(TODAY()-PurchaseOrder[PO Creation Date]<730,"1.5-2 Years",
if(TODAY()-PurchaseOrder[PO Creation Date]< 1095,"2-3 Years","over 3
Years")))))))
Opportunity Type =
VAR rslt = SWITCH(TRUE(),
ItemInstance[Remaining Life based on IB Creation Date]<=0,"Capital
Opp.",
ISBLANK(RELATED('Latest Contract'[Contract Number])),"New Contract
Opp.",
RELATED('Latest Contract'[Header Status])="EXPIRED" &&
RELATED('Latest Contract'[Contract Service Type])="WARRANTY","Exp Warranty Cont
Opp.",
RELATED('Latest Contract'[Header Status])="EXPIRED" &&
RELATED('Latest Contract'[Contract Service Type])="SERVICE","Service Renewal Cont
Opp.",
RELATED('Latest Contract'[Contract Service Type])="WARRANTY", "New
Contract Opp." ,
"Service Renewal Cont Opp."
)
RETURN
rslt
Opportunity Year =
var yr = YEAR(RELATED('Latest Contract'[End Date]))
var curYear = YEAR(TODAY())
return
SWITCH(TRUE(),
ISBLANK(yr),curYear,
MAX(yr,curYear))
Measures:
% <2 Days Invoices = DIVIDE([Entered <2 Days Past Recieved Date],[Total Invoices
With Received Dates],0)
Aging =
if(TODAY()-PurchaseOrder[PO Creation Date]< 120,"00-04 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]< 180,"04-06 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]< 270,"07-09 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]< 365,"10-12 Months",
if(TODAY()-PurchaseOrder[PO Creation Date]<540,"1.0-1.5 Years",
if(TODAY()-PurchaseOrder[PO Creation Date]<730,"1.5-2 Years",
if(TODAY()-PurchaseOrder[PO Creation Date]< 1095,"2-3 Years","over 3
Years")))))))
USD Conversion =
var a = LOOKUPVALUE(FxRateToUsd[Conversion Rate],FxRateToUsd[From
Currency],PurchaseOrder[Currency])
var b = if(PurchaseOrder[Currency]="USD",1,a)
return b
PO Amount Bucket =
var a = 'Purchase Order Bucket'[USD Amount]
return b
Hold Aging = if ([Days On Hold] <= 30, "0-30 Days" , if ([Days On Hold] <= 60 ,
"31-60 Days" , if ([Days On Hold] <= 90 , "61-90 Days" ,
if ([Days On Hold]<= 120 , "91-120 Days" , "Over 120 Days"))))
Hold Aging = if ([Days On Hold] <= 30, "0-30 Days" , if ([Days On Hold] <= 60 ,
"31-60 Days" , if ([Days On Hold] <= 90 , "61-90 Days" ,
if ([Days On Hold]<= 120 , "91-120 Days" , "Over 120 Days"))))
Assigned to Position =
var cntPosition = CALCULATE(COUNTROWS(Control_Functions))
RETURN
IF(cntPosition>0,"Yes","No")
Mansfield Equipment =
switch(true(),
JobOperationMoveTransaction[From Operation Description]="L32 LATHE"
&& JobOperationMoveTransaction[From Intra Operation Step Type]="QUEUE"
&& RELATED(Job_Assembly[Assembly]) in {"260122001"}, "lathe",
"tEST")
L32 = CALCULATE(sum(JobOperationMoveTransaction[Primary
Quantity]),filter(Job_Assembly,Job_Assembly[Assembly] in
{"260122001","260122003"}),filter(JobOperationMoveTransaction,JobOperationMoveTrans
action[From Operation Description]="L32
LATHE"),FILTER(JobOperationMoveTransaction,JobOperationMoveTransaction[From Intra
Operation Step Type]="QUEUE"))
PM
MEASURE
Latest Completion Date = MAX('Preventive_WO'[Completion Date])
column
Last PM Date = CALCULATE(MAX('Preventive_WO'[Completion Date]))
Next PM Date = CALCULATE(MIN('Preventive_WO'[Scheduled Completion
Date]),'Preventive_WO'[Status]="Released")
Active? = IF((ISBLANK('Asset'[Activity End Date]) && NOT(ISBLANK('Asset'[Activity
Start Date]))), "Yes",IF(ISBLANK('Asset'[Activity End Date]),"Unknown","No"))
Active? = IF((ISBLANK('PM Schedule'[To Effective Date])&&NOT(ISBLANK('PM
Schedule'[From Effective Date]))), "Yes",IF(ISBLANK('PM Schedule'[From Effective
Date]),"Unknown","No"))
Shutdown Leadtime (MTTR) = DATEDIFF('Preventive_WO'[Shutdown End
Date],'Preventive_WO'[Actual Start Date],DAY)
Technician =
VAR wip_entity_id = 'Preventive_WO'[WIP Entity ID]
RETURN
CALCULATE(MAX('Operations'[User Name]), FILTER('Operations', 'Operations'[WIP
Entity ID] = wip_entity_id))
Inspection Due =
switch(true(),
'Preventive WO'[Work Order Number] <>BLANK()
&& 'Preventive WO'[Status]="Released" , "Yes","No")
Inspection Due =
switch(true(),
Preventive_WO[Work Order Number] <>BLANK() &&
Preventive_WO[Status]="Released" && ISBLANK('PM Schedule'[To Effective Date])))
Active? = IF(
(
ISBLANK('Asset'[Activity End Date])
&&
NOT(
ISBLANK('Asset'[Activity Start Date])
)), "Yes",IF(ISBLANK('Asset'[Activity End Date]),"Unknown","No"))
Active1? = IF(
(
ISBLANK(Preventive_WO[Work Order Number])
&&
NOT(
ISBLANK(Filter(QA_Discrepancy,QA_Discrepancy[Work_Order])
))
&& Preventive_WO[Status]="Released"),"Yes","No"))
Due? =
var a = Preventive_WO[Status]
var b =Preventive_WO[Work Order Number]
var c = Filter(QA_Discrepancy,QA_Discrepancy[Work_Order])
var d = if(a="Released" && c = BLANK()), "YES","NO"
Return d
RETURN
DIVIDE( qty_issued - qty_required, qty_required, 1)
USD Conversion =
var a = LOOKUPVALUE(FxRateToUsd[Conversion Rate],FxRateToUsd[From
Currency],Payments[Currency])
var b = if(Payments[Currency]="USD",1,a)
return b
PO Amount Bucket =
var a = 'Purchase Order Bucket'[USD Amount]
return b
Aging =
if(TODAY()-PurchaseOrder[Creation Date]< 120,"00-04 Months",
if(TODAY()-PurchaseOrder[Creation Date]< 180,"04-06 Months",
if(TODAY()-PurchaseOrder[Creation Date]< 270,"07-09 Months",
if(TODAY()-PurchaseOrder[Creation Date]< 365,"10-12 Months",
if(TODAY()-PurchaseOrder[Creation Date]<540,"1.0-1.5 Years",
if(TODAY()-PurchaseOrder[Creation Date]<730,"1.5-2 Years",
if(TODAY()-PurchaseOrder[Creation Date]< 1095,"2-3 Years","over 3
Years")))))))
Amount USD = PurchaseOrder[USD Conversion]*PurchaseOrder[Ext Amount]
Avg$/Pos = DIVIDE(SUM(PurchaseOrder[Amount
USD]),CALCULATE(DISTINCTCOUNT(PurchaseOrder[Po Header Id])))
Category_UNSPC Code = 'UNSPC Code Categories'[Category] & "(" & 'UNSPC Code
Categories'[UNSPC Code] & ")"
Shortage =
VAR onhand = CALCULATE(SUM(ComponentItems[Nettable Onhand]))
VAR demand = CALCULATE(SUM(JobComponentRequriements[Quantity Open]))
RETURN
IF(demand>onhand,demand-onhand,BLANK())
Active_customer_count = CALCULATE(
DISTINCTCOUNT(CustomerHeader[Customer Account Id]),
FILTER(CustomerHeader,CustomerHeader[Cust Account Status]="Active")
)
Selected Incident SKU = "FILTERS CURRENTLY APPLIED TO THIS PAGE (from above): " &
UNICHAR(10) & "Selected SKU: " & [Incident List of precendented ProductID values]
Selected Incident SKU & Countries = "FILTERS CURRENTLY APPLIED TO THIS PAGE (from
above): " & UNICHAR(10) & "Selected SKU: " & [Incident List of precendented
ProductID values] & UNICHAR(10) & "Selected Countries: " & [List of Precedented
Country Code values]
Selected Sales Country = "sold in: " & [Sales List of ED_Country_Name values]
Selected Sales SKU = "FILTERS CURRENTLY APPLIED TO THIS PAGE (from above):" &
UNICHAR(10) & "Selected SKU: " & [Sales List of sku values]
Selected Sales SKU & Country = "FILTERS CURRENTLY APPLIED TO THIS PAGE (from
above):" & UNICHAR(10) & "Selected SKU: " & [Sales List of sku values] &
UNICHAR(10) & "Sold In: " & [Sales List of ED_Country_Name values]
Selected TW Product Family = "FILTERS APPLIED TO THIS PAGE (from above): " &
UNICHAR(10) & "TW Product Family: " & [List of TW_Product_Family values]
Selected TW Product Family& Country = "FILTERS APPLIED TO THIS PAGE (from above): "
& UNICHAR(10) & "TW Product Family: " & [List of TW_Product_Family values] &
UNICHAR(10) & "Countries: " & [List of Precedented Country Code values]
distinctcountryid = VALUES(CountryID[ID])
Recommended MIR Dev Code = RELATED('MDR-MIR Device Problem Codes 2'[IMDRF Code])
Incident Country =
--This is precedented
CALCULATE( MAX( Incidents_Precedence[Precedented Country] ),
FILTER(
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID333", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
)
),
[ComplaintID333] =
Incidents[pr_id]
)
)
Incident CountryName =
--This is precedented
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID333", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
)
),
[ComplaintID333] =
Incidents[pr_id]
)
)
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID333", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
)
),
[ComplaintID333] =
Incidents[pr_id]
)
)
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID333", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
)
),
[ComplaintID333] =
Incidents[pr_id]
)
)
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID333", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID333", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
)
),
[ComplaintID333] =
Incidents[pr_id]
)
)
Incident ProductID =
ADDCOLUMNS( Incidents_Precedence,
"ComplaintID22222", CALCULATE(
MAX( Incidents_Precedence[ComplaintID] ),
)
),
[ComplaintID22222] =
Incidents[pr_id]
)
)
--this one is cleanear as it evaluates the inner context rather than simply
compounding CALCULATES on top of one another
CountryName = RELATED(Country[CountryName])
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
CALCULATE( MAX(Incidents_Precedence[Precedence]),
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
CALCULATE( MAX(Incidents_Precedence[Precedence_For_ProductID]),
FILTER( 'Incidents_Precedence',
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
FILTER( Incidents_Precedence, Incidents_Precedence[IMDR Device Code Direct] <>
BLANK() )
)) )
var indirect = CALCULATE(
MAX( Incidents_Precedence[ID] ),
FILTER( Incidents_Precedence,
Incidents_Precedence[ComplaintID] = EARLIER( Incidents_Precedence[ComplaintID] )
),
FILTER( Incidents_Precedence,
Incidents_Precedence[IMDR Device Code Converted From MDR] <> BLANK() ),
FILTER( Incidents_Precedence,
Incidents_Precedence[Precedence_For_ProductID] =
CALCULATE( MAX(Incidents_Precedence[Precedence_For_ProductID]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
FILTER( Incidents_Precedence, Incidents_Precedence[IMDR Device Code Converted From
MDR] <> BLANK() )
)) )
return
if( NOT( ISBLANK( direct ) ), direct, indirect )
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER(Incidents_Precedence[ComplaintID]) ),
FILTER( Incidents_Precedence, Incidents_Precedence[IMDR Investigation Code Direct]
<> BLANK()
) ))
)
var Indirect = CALCULATE(
MAX( Incidents_Precedence[IMDR Investigation Code
Converted From MDR] ),
FILTER( Incidents_Precedence,
Incidents_Precedence[ComplaintID] = EARLIER( Incidents_Precedence[ComplaintID] )
),
FILTER( Incidents_Precedence,
Incidents_Precedence[IMDR Investigation Code Converted From MDR] <> BLANK() ),
FILTER( Incidents_Precedence,
Incidents_Precedence[Precedence_For_ProductID] =
CALCULATE( MAX(Incidents_Precedence[Precedence_For_ProductID]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER(Incidents_Precedence[ComplaintID]) ),
FILTER( Incidents_Precedence, Incidents_Precedence[IMDR Investigation Code
Converted From MDR]
<> BLANK() ) ))
)
return
if( not( isblank( Direct ) ), Direct, Indirect )
CALCULATE( MAX(Incidents_Precedence[Precedence]),
CALCULATE( MAX(Incidents_Precedence[Precedence_For_ProductID]),
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
FILTER( Incidents_Precedence,
Incidents_Precedence[MW Device Code] <> BLANK() ) )
))
CALCULATE( MAX(Incidents_Precedence[Precedence]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
CALCULATE( MAX(Incidents_Precedence[Precedence]),
CALCULATE( MAX(Incidents_Precedence[Precedence_For_ProductID]),
FILTER( 'Incidents_Precedence',
Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
CALCULATE( MAX(Incidents_Precedence[Precedence_For_ProductID]),
FILTER( 'Incidents_Precedence', Incidents_Precedence[ComplaintID] = EARLIER
(Incidents_Precedence[ComplaintID]) ),
EEA CH TR = IF(
(
Sales[ctryabbrev] IN {"CH", "TR"} ||
Sales[ctryabbrev] IN { RELATED( 'EU Codes (2)'[ISO 2 digit] )
}
)
&& Sales[ctryabbrev] <> BLANK(), 1, 0
)
ILP Type =
var WarrantyStartDate = RELATED(ItemInstance[Warranty Start Date])
var DaysBetweenILPWarranty = DATEDIFF(WarrantyStartDate,Contract[Contract Creation
Date],DAY)
return
IF (Contract[Service Type]<>"Service",
BLANK(),
IF (ISBLANK(WarrantyStartDate),
"No Warranty",
IF (DaysBetweenILPWarranty<=90,
"POS with Capital",
IF (DaysBetweenILPWarranty>90 && DaysBetweenILPWarranty <365,
"POS",
IF (DaysBetweenILPWarranty>365 && DaysBetweenILPWarranty <7*365,
"Renewal")
))))
Contract# = CONVERT(Contract_Billing[Contract_Number],STRING)
Opportunity Type =
VAR rslt = SWITCH(TRUE(),
ItemInstance[Remaining Life based on IB Creation Date]<=0,"Capital
Opp.",
ISBLANK(RELATED('Latest Contract'[Contract Number])),"New Contract
Opp.",
RELATED('Latest Contract'[Header Status])="EXPIRED" &&
RELATED('Latest Contract'[Contract Service Type])="WARRANTY","Exp Warranty Cont
Opp.",
RELATED('Latest Contract'[Header Status])="EXPIRED" &&
RELATED('Latest Contract'[Contract Service Type])="SERVICE","Service Renewal Cont
Opp.",
RELATED('Latest Contract'[Contract Service Type])="WARRANTY", "New
Contract Opp." ,
"Service Renewal Cont Opp."
)
RETURN
rslt
Opportunity Year =
var yr = YEAR(RELATED('Latest Contract'[End Date]))
var curYear = YEAR(TODAY())
return
SWITCH(TRUE(),
ISBLANK(yr),curYear,
MAX(yr,curYear))
Renewal Opportunity =
if(ItemInstance[Remaining Service Life]>0 && ItemInstance[Recent ILP End
Date]<=TODAY()
,"Yes",
"No"
)
Latest Diagnostics =
SUMMARIZE(FILTER(RELATEDTABLE(RepairOrderDiagnosticCodes),RepairOrderDiagnosticCode
s[RANK]=1),RepairOrderDiagnosticCodes[Diagnostic Code])
RevenueRecognition = CROSSJOIN(RevenueRecognitionSummary,RevenueRecogntionPeriods)
RRAmount = if(
RevenueRecognition[LastDayofMonth]>=RevenueRecognition[Start Date] &&
RevenueRecognition[LastDayofMonth]<=RevenueRecognition[End Date],
RevenueRecognition[MonthlyAmount],0
)
LastDayofMonth = ENDOFMONTH(RevenueRecognitionDates[Date])
RevenueRecognitionDates =
CALENDAR(
DATE ( 2019, 1, 1 ),
DATE ( 2025, 12, 1 ))
LastDayofMonth = ENDOFMONTH(RevenueRecognitionDates[Date])
RevenueRecognitionSummary = SUMMARIZE(
FILTER(ALL(Contract),(NOT (Contract[Line Status] IN
{"Expired","Cancelled"} && Contract[Amount]>0)) ) ,
Contract[Operating Unit],
Contract[Contract Number],
ItemInstance_Owner[Owner Name],
Contract[Service Type],
ItemInstance_Item[Item Number],
ItemInstance[Serial Number],
Contract[Line Service Name],
Contract[Start Date],
Contract[End Date],
Contract[Line Status],
"Amount",
sum(Contract[Amount]))
MonthlyAmount =
ROUND(DIVIDE(RevenueRecognitionSummary[Amount],RevenueRecognitionSummary[Months],0)
,2)
Months = DATEDIFF(RevenueRecognitionSummary[Start
Date],RevenueRecognitionSummary[End Date]+1,MONTH)
RevenueRecogntionPeriods = VALUES(RevenueRecognitionDates[LastDayofMonth])
Latest Notes =
CALCULATE(MAX(RepairOrderEstimateNotes[Notes]),RELATEDTABLE(RepairOrderEstimateNote
s))
ServiceRequest_ItemInstance = ALL(ItemInstance)
SR Calendar = ALL('Calendar')
*********************************
Backordered = IF(Delivery[Released Status Code]="B","Yes","No")
Distinct Lines =
Var Cnt = CALCULATE(DISTINCTCOUNT(SalesOrder[Line ID]))
Return
IF(ISBLANK(Cnt),0,Cnt)
Distinct Order =
Var Cnt = CALCULATE(DISTINCTCOUNT(SalesOrder[Order Number]))
Return
IF(ISBLANK(Cnt),0,Cnt)
Shortage Quantity =
var OQ = SUM(SalesOrder[Ordered Quantity])
var AQ = sum(Onhand[Reservable Onhand])
var SQ= OQ-AQ
Return
SQ
Aged CS BackOrder =
SWITCH(TRUE(), Related(SalesOrder_TransactionType[Order Type]) IN {
"AT Charge Sheet Order",
"AT Standard Order",
"AU Standard Order",
"BE Product Request",
"CA Sample Order",
"CA Standard Order",
"CH Charge Sheet Order",
"CH Demo Order",
"DE Sales Credit Only Order",
"DE Sales Standard Order",
"DE Standard Order",
"FR Standard Order",
"ILS Bill Only Order",
"ILS Credit Only Order",
"ILS Standard Order",
"JP Sample Order",
"JP Standard Order",
"UK EDC Set Shipment"
}
&& RELATED(SalesOrder[On Hold])="No" && RELATED( SalesOrder[On
Backorder])="Yes" ,1,0)
Duplicate =
var od = RELATED(SalesOrder[Order Date])
var PrevOd = PREVIOUSDAY(SalesOrder[Order Date])
var OrdCnt= DISTINCTCOUNT(SalesOrder[Order Number])
Return
1
Invoice Hold =
/*var cnt= CALCULATE(COUNTROWS(DISTINCT(SalesOrder_Holds[Order Line
ID])),Holds_Definition[Hold Name] IN {"INTG Invoice", "INTG Invoice Interface
Hold(H)", "INTG Invoice Interface Hold(L)", "INTG IT Invoice Interface Hold"},
ALLEXCEPT(Order_Exception,Order_Exception[Line ID])) */
var cnt = CALCULATE(COUNTROWS(DISTINCT(SalesOrder_Holds[Order Line
ID])),CONTAINSSTRING(Holds_Definition[Hold Name] ,"INTG Invoice"),
ALLEXCEPT(Order_Exception,Order_Exception[Line ID]))
Return
SWITCH(TRUE(),cnt>0,1,0)
No Customer PO Price =
SWITCH(TRUE(),ISBLANK(RELATED(SalesOrder[Customer Net Price]))
&& RELATED(SalesOrder_TransactionType[Order Type Category])="Standard Order"
&& RELATED(SalesOrder[Line Status])="Entered"
,1,0)
Obsolete =
var Reserved = RELATED(Onhand[Reserved])
var Nettable = RELATED(Onhand[Nettable Onhand])
var OrderQuantity = RELATED(SalesOrder[Ordered Quantity])
Return
SWITCH (
TRUE (),
RELATED ( SalesOrder_Items[Item Status] ) = "Obsolete"
&& Nettable = 0 && Reserved < OrderQuantity, 1,
0
)
,1,0)
RDC Exports Not Dropped = SWITCH(TRUE(),
RELATED(SalesOrder_operatingUnit[Operating Unit])="OU United States" &&
RELATED(SalesOrder_Warehouse[Warehouse Code])="120" &&
RELATED(SalesOrder_ShipToCustomer[Ship To Country])<>"US" &&
RELATED(SalesOrder[Most Recent Delivery Status])="Ready to Release" &&
RELATED ( SalesOrder[Line Status] ) = "AWAITING_SHIPPING"
&& RELATED ( SalesOrder[On Backorder] ) = "No"
&& RELATED ( SalesOrder[On Hold] ) = "No"
&& RELATED ( SalesOrder[Future Date] ) = "No", 1,
0
)
Rx License Hold =
var cnt= CALCULATE(COUNTROWS(DISTINCT(SalesOrder_Holds[Order Line
ID])),Filter(ALLNOBLANKROW(Holds_Definition[Hold Name]),Holds_Definition[Hold
Name]="INTG RX LICENSE INFO HOLD (L)"),
ALLEXCEPT(Order_Exception,Order_Exception[Line ID]))
Return
SWITCH(TRUE(),cnt>0,1,0)
DCodeCountry =
RELATED(SalesOrder_Items[DCode])&"-"&RELATED(SalesOrder_ShipToCustomer[End
Destination Country])
DST_Flag = RELATED(dim_calendar[dst_flag])
/*
var cd= DATEDIFF(SalesOrder[Order Date],NOW(),HOUR)
var holdCnt= CALCULATE(COUNTROWS(DISTINCT(SalesOrder_Holds[Order Line
ID])),Holds_Definition[Hold Name] in {"Manual Allocation Hold (L)","EDI Price Hold
(H)","EDI Duplicate PO Hold (H)","INTG Duplicate PO Hold (H)","Price Override Hold
( H )","Price Override Hold ( L )"})
Return
Switch(True(),holdCnt>0 && SalesOrder[Order Status]="ENTERED" && cd>24,1,0) */
)*/
)) */
Future Date =
var rd = SalesOrder[Request Date]
var td = TODAY()
var ssd = SalesOrder[Schedule Ship Date]
var rslt = if (OR(rd>td,ssd>td),"Yes","No")
RETURN
rslt
International_Flag = SWITCH(TRUE(),
RELATED(SalesOrder_ShipToCustomer[ShipTo_Flag])=RELATED(SalesOrder_Warehouse[ShipFr
om_Flag]),"No","Yes")
Return
Switch(True(),Cnt>=1 && SalesOrder[Line Status]="AWAITING_SHIPPING" &&
ReservQty<=0 ,1,0) */
VAR cnt =
CALCULATE (
COUNTROWS ( DISTINCT ( SalesOrder_HoldTypes[Order Line ID] ) ),
CONTAINSSTRING(SalesOrder_HoldTypes[Hold Name],"Manual Allocation Hold
(L)") && NOT(CONTAINSSTRING(SalesOrder_HoldTypes[Hold Name],"Credit Check
Failure")),ALLEXCEPT(SalesOrder,SalesOrder[Line ID]))
var reservableOnhand = RELATED(Onhand[Reservable Onhand])
Return
Switch(True(), cnt>=1 && SalesOrder[Line Status]="AWAITING_SHIPPING" &&
ISBLANK(SalesOrder[Reserved Quantity]) && SalesOrder[BackOrder Quantity]>=1 &&
reservableOnhand>=1 ,1,0)
On Backorder =
VAR bo = CALCULATE(COUNT(Delivery[Delivery Detail ID]),Delivery[Released Status
Code]="B")
VAR rslt = SWITCH(TRUE(),
bo>0,"Yes",
"No")
RETURN
rslt
// "TOSHIO.AMO" //
VAR TZ_DST0 =
LOOKUPVALUE(
DIM_R12_User_Timezone[EST_Offset_DST],
DIM_R12_User_Timezone[User_Name], usr
)
VAR TZ_DST1 =
ABS(LOOKUPVALUE (
DIM_R12_User_Timezone[EST_Offset_DST],
DIM_R12_User_Timezone[User_Name], usr
))
VAR TZ_NoDST0 =
LOOKUPVALUE (
DIM_R12_User_Timezone[EST_Offset_NoDST],
DIM_R12_User_Timezone[User_Name], usr
)
VAR TZ_NoDST1 =
ABS(LOOKUPVALUE (
DIM_R12_User_Timezone[EST_Offset_NoDST],
DIM_R12_User_Timezone[User_Name], usr
))
VAR UN =
LOOKUPVALUE (
DIM_R12_User_Timezone[User_Name],
DIM_R12_User_Timezone[User_Name], usr
)
VAR DST =
SELECTEDVALUE ( SalesOrder[DST Flag] ) // Var FormatStr = "mm/dd/yyyy hh:mm:ss"
//var Od = format(HASONEVALUE(SalesOrder[Order Date]),FormatStr)
//var OD_DST_Y = IF(DST="Y",Od+TZ_DST,Od+TZ_NoDST)
VAR OD =
SWITCH (
TRUE (),
ISBLANK(TZ_DST0),orderDate,
DST = "Y", IF(TZ_DST0 <0, orderDate - TIME ( TZ_DST1, 0,
0 ),orderDate+TIME(TZ_DST0,0,0)),
DST = "N", IF(TZ_NoDST0 <0 , orderDate - TIME ( TZ_NoDST1, 0, 0 ),
orderDate + TIME(TZ_NoDST0,0,0))
)
RETURN
/*IF( usr=UN,
OD,orderDate) */
OD
VAR TZ_DST =
LOOKUPVALUE (
DIM_R12_User_Timezone[EST_Offset_DST],
DIM_R12_User_Timezone[User_Name], usr
)
VAR TZ_NoDST =
LOOKUPVALUE (
DIM_R12_User_Timezone[EST_Offset_NoDST],
DIM_R12_User_Timezone[User_Name], usr
)
VAR UN =
LOOKUPVALUE (
DIM_R12_User_Timezone[User_Name],
DIM_R12_User_Timezone[User_Name], usr
)
VAR DST =
SELECTEDVALUE ( SalesOrder[DST Flag] ) // Var FormatStr = "mm/dd/yyyy hh:mm:ss"
VAR OD =
SWITCH (
TRUE (),
ISBLANK(TZ_DST),orderDate,
DST = "Y", orderDate + TIME ( TZ_DST, 0, 0 ),
DST = "N", orderDate + TIME ( TZ_NoDST, 0, 0 )
)
RETURN
OD
*/
Orderability Country =
SWITCH (
TRUE (),
// NOT ( ISBLANK ( SalesOrder[Destination Country] ) ), SalesOrder[Destination
Country],
NOT ( ISBLANK ( RELATED ( SalesOrder_DeliverToCustomer[Deliver To
Country] ) ) ), RELATED ( SalesOrder_DeliverToCustomer[Deliver To Country] ),
RELATED ( SalesOrder_ShipToCustomer[Ship To Country] )
)
Price Holds =
var holdCnt= CALCULATE(COUNTROWS(DISTINCT(SalesOrder_Holds[Order Line
ID])),Holds_Definition[Hold Name] in {"EDI Item Price Hold (L)","EDI Price Hold
(H)","Manual Pricing Hold (H)","Manual Pricing Hold (L)"})
Return
Switch(True(),holdCnt>0 && RELATED(SalesOrder_OperatingUnit[Operating Unit])="OU
United States" && Related(SalesOrder_ShipToCustomer[Ship To Region])="North America
Domestic" && RELATED(SalesOrder_TransactionType[Order Type])="ILS Standard
Order",1,0)
RADB Country =
var destinationCountry = SalesOrder[Destination Country]
var deliverCountry = RELATED(SalesOrder_DeliverToCustomer[Deliver To Country])
var shipCountry = RELATED(SalesOrder_ShipToCustomer[Ship To Country])
return
COALESCE(destinationCountry,deliverCountry,shipCountry)
RestockingFee_Discrepancy =
var ExpectedRestockingFee =CALCULATE( SUM(SalesOrder[Expected Restocking Fee ($)]))
//var ActualRestockingFre = CALCULATE(sum(OpenOrder_Restocking_Fee[Restocking
Fee]),
FILTER(OpenOrder_Restocking_Fee,OpenOrder_Restocking_Fee[Header_ID]=VALUES(SalesOrd
er[Header ID])))
Var ActualRestockingFre= SELECTEDVALUE(SalesOrder[RestockingFee])
Return
//ActualRestockingFre
--SELECTEDVALUE(SalesOrder[RestockingFee])
IF( (ExpectedRestockingFee-ActualRestockingFre >2) || (ActualRestockingFre-
ExpectedRestockingFee)>2,"Y", "N")
Rows in Backorder =
VAR cnt = CALCULATE(DISTINCTCOUNT(Delivery[Order Line ID]),
Delivery[Released Status Code]="B")
VAR rslt = IF(ISBLANK(cnt),0,cnt)
RETURN
rslt
TZ_DST =
LOOKUPVALUE (
DIM_R12_User_Timezone[EST_Offset_DST],
DIM_R12_User_Timezone[User_Name], [UserName]
)
UN =
LOOKUPVALUE (
DIM_R12_User_Timezone[User_Name],
DIM_R12_User_Timezone[User_Name], [UserName] )
UserName = LEFT (
USERPRINCIPALNAME(),
LEN ( USERPRINCIPALNAME()) - SEARCH ( "@", USERPRINCIPALNAME() ))
UserName_Prin =
var x= USERPRINCIPALNAME()
Return
LEFT(x,SEARCH("@",x)-1)
Hold Aging =
VAR d = SalesOrder_Holds[Days on Hold]
VAR rslt = SWITCH(TRUE(),
d>90 , "90+ Days",
d>=61, "61-90 Days",
d>=31, "31-60 Days",
d>=11, " 11-30 Days",
d>=6, " 06-10 Days",
d>=3, " 03-05 Days",
d>=0, " 00-02 Days")
RETURN
rslt
EU Flag =
SWITCH (
TRUE (),
RELATED ( SalesOrder_Warehouse[ShipFrom_Flag] )
IN { "EU" }
&& (
RELATED ( SalesOrder_Items[DFF ECCN 135] ) = " "
|| RELATED ( SalesOrder_Items[DFF EU Commodity Code] ) = " "
), "Yes",
"No"
)
SW Flag =
SWITCH (
TRUE (),
RELATED ( SalesOrder_Warehouse[ShipFrom_Flag] )
IN { "SW" }
&& (
RELATED ( SalesOrder_Items[EU Commodity Code in 191] ) = " "
|| RELATED ( SalesOrder_Items[DFF ECCN 191] ) = " "
), "Yes",
"No"
)
UK Flag =
SWITCH (
TRUE (),
RELATED ( SalesOrder_Warehouse[ShipFrom_Flag] )
IN { "UK" }
&& (
RELATED ( SalesOrder_Items[EU Commodity Code in 415] ) = " "
|| RELATED ( SalesOrder_Items[DFF ECCN 415] ) = " "
), "Yes",
"No"
)
USA Or PR Flag =
SWITCH (
TRUE (),
RELATED ( SalesOrder_Warehouse[ShipFrom_Flag] )
IN { "US", "PR" }
&& (
RELATED ( SalesOrder_Items[DFF Schedule B] ) = " "
|| RELATED ( SalesOrder_Items[DFF ECCN] ) = " "
|| RELATED ( SalesOrder_Items[DFF License Required] ) = ""
), "Yes",
"No"
)
Division =
//VAR dvsn = IF(SalesOrder_Items[DCode]="DEFLT",SalesOrder_Items[Division Item
Level],RELATED(DCodeGlobalProductRollup[Rollup Level1]))
VAR dvsn = SalesOrder_Items[Division Item Level]
VAR rslt = SWITCH(TRUE(),
dvsn in {"RECON","OTT"},"OTT",
dvsn IN {"SSS","Codman","NEURO","INSTR"},"CSS",
"Others")
RETURN
rslt
Int'l OU Group =
SWITCH(TRUE(),
SalesOrder_OperatingUnit[Operating Unit] IN {"France Sales OU",
"Germany Sales OU",
"Swiss Sales OU",
"Netherlands Sales OU",
"OU Belgium",
"OU Italy",
"OU UK",
"OU Ireland"}, "EU OTT"
)
ShipFrom_Flag = SWITCH(TRUE(),SalesOrder_Warehouse[Country] IN
{"AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IE","IT","LV","L
T","LU","MT","NL","PL","PT","RO","SK","SI","ES","SE"},"EU",SalesOrder_Warehouse[Cou
ntry])
// ,SalesOrder_Warehouse[Country] IN {"US","PR"} -- Removed this as per update in
update in logic
Measure =
VAR _select =
SELECTEDVALUE ( Slicer[Name] )
RETURN
IF (
_select = "Estimate Name",
CALCULATE (
MAX ( Append1[Value] ),
FILTER ( Append1, Append1[Column] <> "Hidden Name" )
),
CALCULATE (
MAX ( Append1[Value] ),
FILTER ( Append1, Append1[Column] <> "Estimate Name" )
)
)
******************************************************
Measures created as shown:
Earliest Receipt Date = CALCULATE(MIN('Material Transactions'[Transaction Date]),
'Material Transactions'[Transaction_Type_ID]=18)
Latest Ship Date = CALCULATE(MAX('Material Transactions'[Transaction
Date]),'Material Transactions'[Transaction_Type_ID]=62)
Recipt to Ship Cycle Time (Days) = DATEDIFF([Earliest Receipt Date],[Latest Ship
Date],DAY)
RETURN
CALCULATE(
Min('Material Transactions'[Transaction Date]),
ALL('Material Transactions'),
'Material Transactions'[Transaction_Type_ID]=18,
'Item Basic'[Item Number] = item_number,
'Item Basic'[Item Description] = item_description,
'Material Transactions'[Lot Number] = lot_number)
var po = SUMMARIZE(
FILTER('Material Transactions','Material
Transactions'[Organization_ID]=2923 && 'Material Transactions'[Transaction_Type_ID]
=18),
'Material Transactions'[Organization_ID],'Material
Transactions'[Inventory_Item_ID],'Material Transactions'[Lot Number],
"PO Receipt Date",MIN('Material Transactions'[Transaction Date]))
RETURN
rslt
-- Anasco issue
Technicians =
var selectedOrg =SELECTEDVALUE('Preventive WO'[org])
RETURN
if (selectedOrg="165",techn165,techn)
Org = RELATED(Activity[org])
***********************************************************************************
***********
Raw Material QTY calculation in BOM resource report
Raw Mat QTY =
var DE1 =IF(ISBLANK('BOM Oracle'[DE.1]),1,'BOM Oracle'[DE.1])
var DE2 =IF(ISBLANK('BOM Oracle'[DE.2]),1,'BOM Oracle'[DE.2])
var DE3 =IF(ISBLANK('BOM Oracle'[DE.3]),1,'BOM Oracle'[DE.3])
var DE4 =IF(ISBLANK('BOM Oracle'[DE.4]),1,'BOM Oracle'[DE.4])
var DE5 =IF(ISBLANK('BOM Oracle'[DE.5]),1,'BOM Oracle'[DE.5])
var DE6 =IF(ISBLANK('BOM Oracle'[DE.6]),1,'BOM Oracle'[DE.6])
Supplier Name =
// VAR org_item = 'BOM Oracle'[COrgID-ItemID]
VAR from_sourcing = FIRSTNONBLANK('Sorcing Rule'[Vendor_Name], TRUE())
VAR from_quotation = CALCULATE( FIRSTNONBLANK(PO[Vendor_Name], TRUE()),
FILTER(PO, PO[Order Type]="QUOTATION") )
VAR from_bpa = CALCULATE( FIRSTNONBLANK(PO[Vendor_Name], TRUE()),
FILTER(PO, PO[Order Type]="BLANKET") )
VAR from_asl = FIRSTNONBLANK(ASL[Vendor_Name], TRUE())
VAR from_standard = CALCULATE( FIRSTNONBLANK(PO[Vendor_Name], TRUE()),
FILTER(PO, PO[Order Type]="STANDARD") )
// RETURN from_sourcing
***********************
Break QTY =
CALCULATE(
FIRSTNONBLANK(PO[Break Quantity], TRUE()),
FILTER(
PO, OR(
PO[Order Type] = "BLANKET",
PO[Order Type] = "QUOTATION"))
)
Period_EndDate_LYr =
var period_endLYr=ENDOFMONTH(DATEADD('Period Not Linked'[End_Date],-1,YEAR))
var x= IF(NOT(ISBLANK(period_endLYr)),period_endLYr,0)
return x
MTD Last Year Same Period =
VAR period_name_TYr = 'PL BS Trend Primary Imported'[Period Name]
VAR period_start_LYr = LOOKUPVALUE('Period Not
Linked'[Period_StartDate_LYr], 'Period Not Linked'[Period_Name], period_name_TYr)
VAR period_end_LYr = LOOKUPVALUE('Period Not Linked'[Period_EndDate_LYr],
'Period Not Linked'[Period_Name], period_name_TYr)
VAR mtd_total_LYr = CALCULATE(
SUM('PL BS Trend Primary Imported'[Period Activity]),
'GL Period'[Start_Date]>=period_start_LYr && 'GL
Period'[End_Date]<=period_end_LYr,ALLEXCEPT('PL BS Trend Primary Imported','PL BS
Trend Primary Imported'[Period Activity]))
****************************
1 to many , to 1 combination problem
Invoice Amount =
CALCULATE( SUM(FieldService_Invoices[Invoice Line Amount]),
ALLEXCEPT(FieldService_Invoices,
FieldService_Invoices[Order Number]))