← Back to Chapters

Invoking Basics

? Power Query Editor – Invoking Basics

? QUICK OVERVIEW

Invoking in Power Query means applying a reusable custom function on table data. Instead of repeating logic again and again, you write it once and reuse it safely.

? KEY CONCEPTS

  • Function A reusable logic written in Power Query (M).
  • Invoke Applying function logic on table rows.
  • Parameter Input value passed to the function.
  • Row Context Function runs row by row.

? SYNTAX / THEORY

? Function Syntax
// Basic Power Query function structure
(parameter as datatype) =>
let
result = parameter
in
result

? PRACTICE SAMPLE DATA

? View Sample CSV
// Sales data used for invoking practice
OrderID,Product,Quantity,Price
1,Mobile,2,15000
2,Laptop,1,45000
3,Mouse,5,500
4,Keyboard,4,800
5,Monitor,3,12000

? FUNCTION CREATION

? View Function Code
// Function to double quantity value
(qty as number) =>
let
result = qty * 2
in
result

? INVOKING FUNCTION

? View Invoke Step
// Auto-generated invoke logic
Table.AddColumn(Source,"DoubleQty",each fnDoubleQty([Quantity]))

? LIVE OUTPUT EXPLANATION

Each row in Quantity column is passed into the function and multiplied by 2. A new column is generated automatically.

? USE CASES

  • GST / VAT calculation
  • Discount logic standardization
  • Currency conversion
  • Employee incentive calculation
  • Reusable data cleansing rules

⚙️ INTERACTIVE EXAMPLE

Power Query Simulator: Practice Invoking a Custom Function

Write a formula logic using qty (e.g., qty * 2 or qty * 0.18) to see how it invokes row-by-row.

OrderID Product Quantity (qty) fnLogic([qty])
 

✅ TIPS & BEST PRACTICES

✔ Prefix function names with fn
✔ Keep logic small and reusable
✔ Always define parameter data types
✔ Comment M-code properly

? TRY IT YOURSELF

Task 1: Create function → Quantity × Price
Task 2: Create GST function → 18%
Task 3: Apply discount if Quantity > 3