# 8.4 Invoke Custom Function

Source: https://ravindrabagale.com/mr/powerbi/ch08-adding-columns-power-query-add-column-tab-and/8-4-invoke-custom-function.html
Language: mr (Marathi with English technical terms)

एकच logic Blinkit आणि Amazon Now queries मध्ये वापरायचं किंवा प्रत्येक page साठी request करायची असेल तर reusable function उपयोगी.

Home › New Source › Blank Query › Advanced Editor मध्ये code paste करा.

Query ला fnDeliveryBand नाव द्या.

Orders › Add Column › Invoke Custom Function निवडा.

Column Delivery Band; function fnDeliveryBand; mins साठी Delivery Time Mins column द्या.

Result Text ठेवा आणि दुसऱ्या query मध्येही हाच function वापरा.

// fnDeliveryBand
(mins as nullable number) as text =>
    if mins = null then "Not delivered"
    else if mins <= 10 then "0-10 min"
    else if mins <= 15 then "11-15 min"
    else if mins <= 30 then "16-30 min"
    else "30+ min"

Band limits बदलल्यावर एकच function edit करावं लागतं. Invalid negative minutes वेगळे flag करून ठेवा.

Practice

fnPaymentGroup(mode as text) as text बनवा: UPI / Card / Wallet → Digital, बाकी Cash असा practice rule. प्रत्यक्ष data मध्ये Unknown व इतर modes साठी स्वतंत्र नियम ठरवा.

रवींद्र बागले यांची tip

प्रत्येक हजारो rows साठी web API call करणारा function refresh slow करू शकतो. आधी काही rows वर test करा. Custom function मुळे folding थांबतो का तपासा.
