{"id":40298,"date":"2025-01-29T12:58:58","date_gmt":"2025-01-29T07:28:58","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=40298"},"modified":"2025-03-12T11:50:09","modified_gmt":"2025-03-12T06:20:09","slug":"how-to-use-user-defined-functions-and-user-defined-types-in-canvas-apps","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2025\/01\/how-to-use-user-defined-functions-and-user-defined-types-in-canvas-apps\/","title":{"rendered":"How to Use User-Defined Functions and User-Defined Types in Canvas Apps"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40320\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"How to Use User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1925\" height=\"1100\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1925w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x171.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x585.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x439.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1536x878.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/How-to-Use-User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x377.png 660w\" sizes=\"(max-width: 1925px) 100vw, 1925px\" \/><\/p>\n<p>Building Canvas Apps in PowerApps presents a challenge. Microsoft has provided great built-in functions, but what if your App needed something other than the built-in functions? You would have to create workarounds\u2014repeating formulas, juggling nested logic, and spending extra time managing it all. It worked, but it wasn\u2019t ideal.<\/p>\n<p>Now, Microsoft is upgrading the process by introducing the <strong>User-Defined Functions (UDFs)<\/strong>! This upcoming feature will let you create your own custom functions, perfectly tailored to your App\u2019s needs.<\/p>\n<p>Here\u2019s why it\u2019s useful:<\/p>\n<ul>\n<li>Reuse Your Logic: Write it once, use it everywhere. No more repetitive code!<\/li>\n<li>Simple Updates: Fix or tweak your function in one place, and it updates across your App.<\/li>\n<\/ul>\n<p>Imagine you are building a Tax Calculator feature for Business and Salary income in your App. Previously, you might have to write the same formula on different buttons to calculate taxes for salary and business income.<\/p>\n<p>With User-Defined Functions (UDFs), you can simply create a function like TaxCalculator() and reuse it across forms, pages, and buttons. Efficient and consistent, right?<\/p>\n<p>Moreover, UDFs can be combined with user-defined types<strong> (UDTs)<\/strong> to handle complex data like records or tables in one go.<\/p>\n<p>User-Defined Types (UDTs<strong>)<\/strong> are advanced features in PowerApps that enable App developers to create custom data types.<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>Launch your application in <a href=\"https:\/\/make.powerapps.com\/\" target=\"_blank\" rel=\"noopener\">Power Apps<\/a>, then go to <strong>Settings <\/strong>in the command bar and select <strong>Updates<\/strong>. Next, within the <strong>Experimental <\/strong>tab, turn on both the <strong>User-Defined Functions <\/strong>and <strong>User-Defined types<\/strong> options to start adding UDFs and UDTs in your App.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40299\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/1User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1344\" height=\"636\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/1User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1344w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/1User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x142.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/1User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x485.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/1User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x363.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/1User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x312.png 660w\" sizes=\"(max-width: 1344px) 100vw, 1344px\" \/><\/p>\n<h2><strong>Example Use Case of User-Defined Function<\/strong><\/h2>\n<p>Let\u2019s explore a simple example to see how User-Defined Functions (UDFs) can make your app smarter and cleaner.<\/p>\n<p>Imagine you have a tax calculator over two forms: one for business owners and another for salaried employees. Each form has similar fields that are used to calculate tax for business and salary.<\/p>\n<p>Depending on which button is clicked, the app should calculate the tax based on the user\u2019s input fields like income, tax rate, deductions, etc.<\/p>\n<p>Before UDFs, you might have written separate logic for each button on every form, making your app cluttered and hard to manage. But with UDFs, you can create a single reusable function and simply adjust the parameters based on the button clicked and the form it\u2019s used on.<\/p>\n<p>Here\u2019s how it works:<\/p>\n<p><strong>Step-by-Step Process to Set <\/strong><strong>Up UDFs:<\/strong><\/p>\n<p>Open your <strong>Canvas App<\/strong> in Power Apps.<\/p>\n<ul>\n<li>Navigate to the <strong>Variables<\/strong> section in the left panel.<\/li>\n<li>Click on the <strong>+ New<\/strong> button.<\/li>\n<li>Choose <strong>{x} Named Formula<\/strong>.<\/li>\n<li>Once the Formula Bar appears, type in the definition of the UDFs using Power Fx syntax.<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40300\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/2User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1361\" height=\"607\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/2User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1361w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/2User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x134.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/2User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x457.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/2User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x343.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/2User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x294.png 660w\" sizes=\"(max-width: 1361px) 100vw, 1361px\" \/><\/p>\n<p>Below is a simple function that is added to calculate the tax based on the income and other details given by the user.<\/p>\n<p><strong>UDF Function:<\/strong><\/p>\n<p>TaxCalculator2(<\/p>\n<p>Income: Number,<\/p>\n<p>TaxRate: Number,<\/p>\n<p>Deductions: Number,<\/p>\n<p>Allowances: Number,<\/p>\n<p>TDS: Number<\/p>\n<p>): Number =<\/p>\n<p>(Income &#8211; Deductions &#8211; Allowances) * (TaxRate \/ 100) &#8211; TDS;<\/p>\n<p>Add this <strong>UDF function<\/strong> inside the PowerFx formula after selecting <strong>Named Formula<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40301\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/3User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"848\" height=\"403\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/3User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 848w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/3User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x143.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/3User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x365.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/3User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x314.png 660w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/p>\n<p>Now I will be calling this function on multiple events, and in our scenario, I will be calling it on the click of <strong>Calculate<\/strong> buttons for business and salary income.<\/p>\n<p>Here is my Salary tax calculator on the Canvas App form:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40302\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/4User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"582\" height=\"688\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/4User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 582w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/4User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-254x300.png 254w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/p>\n<p>Here is another Business income tax calculator on another Canvas App form:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40303\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/5User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"601\" height=\"777\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/5User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 601w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/5User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-232x300.png 232w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/p>\n<p>I have added a function on click of these buttons as you can see below, <strong>OnSelect<\/strong> is my event which will call my function named TaxCalculator()<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40304\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/6User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"959\" height=\"388\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/6User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 959w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/6User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x121.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/6User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x311.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/6User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x267.png 660w\" sizes=\"(max-width: 959px) 100vw, 959px\" \/><\/p>\n<pre class=\"lang:css gutter:true start:1\">Notify($\"{TaxCalculator(\r\n\r\n<em>business_profit<\/em>.Text,\r\n\r\n<em>business_taxRate<\/em>.Text,\r\n\r\n<em>business_deductions<\/em>.Text,\r\n\r\n<em>business_allowance<\/em>.Text,\r\n\r\n<em>business_tds<\/em>.Text)}\"\r\n\r\n)<\/pre>\n<p>Similarly, if the user clicks the Button added to the Salary Tax Calculator form then the same function will be triggered :<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40305\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/7User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1037\" height=\"404\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/7User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1037w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/7User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x117.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/7User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x399.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/7User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x299.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/7User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x257.png 660w\" sizes=\"(max-width: 1037px) 100vw, 1037px\" \/><\/p>\n<pre class=\"lang:css gutter:true start:1\">Notify($\"{TaxCalculator(\r\n\r\nsalary_income.Text,\r\n\r\nsalary_taxRate.Text,\r\n\r\nsalary_deductions.Text,\r\n\r\nsalary_allowance.Text,\r\n\r\nsalary_tds.Text)}\"\r\n\r\n)<\/pre>\n<p>The different parameter is passed on the click of both buttons but the function is the same which is TaxCalculator().<\/p>\n<p>In the current example for Salary Tax Calculation, we are taking inputs like Income, Tax Rate, Allowance, TDS, and Deductions from the form fields that the user will fill in.<\/p>\n<p>Based on these inputs, the app calculates the tax and displays the result to the user, ensuring accurate and dynamic calculations.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40306\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/8User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1110\" height=\"936\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/8User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1110w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/8User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x253.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/8User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x863.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/8User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x648.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/8User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x557.png 660w\" sizes=\"(max-width: 1110px) 100vw, 1110px\" \/><\/p>\n<p>Similarly, to Calculate the Business Income Tax, we have added a few fields on form page like, Gross revenue, COGs, Operating Expenses, Net Profit, Income, Deductions, Allowance, and TDS.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40307\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/9User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1272\" height=\"1052\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/9User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1272w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/9User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x248.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/9User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x847.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/9User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x635.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/9User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x546.png 660w\" sizes=\"(max-width: 1272px) 100vw, 1272px\" \/><\/p>\n<h2><strong>Example Use Case for User-Defined Types<\/strong><\/h2>\n<p>Let\u2019s dive into an example that shows the use case of <strong>User-Defined Types (UDTs)<\/strong> in simplifying how we work with custom or structured data type.<\/p>\n<p>Imagine you\u2019re building an App which is a <strong>product inventory system<\/strong> that handles orders. Each order has details like the Order ID, Customer Name, Status, Delivery Date, and more. Before UDTs, you\u2019d manage these fields individually, which could lead to messy code and repeated work.<\/p>\n<p>With UDTs, you can define a custom type to group all these fields into a single, reusable structure.<\/p>\n<p>The basic syntax to define a UDT looks like this:<\/p>\n<p><strong>Step 1: Get the Data<\/strong><\/p>\n<pre class=\"lang:css gutter:true start:1\">Products =[\r\n{ProductID:\"P001\",ProductName:\"Laptop\",Price: 1000,StockQuantity:50},\r\n\r\n{ProductID: \"P002\", ProductName: \"Smartphone\", Price: 500, StockQuantity: 100},\r\n\r\n{ProductID: \"P003\", ProductName: \"Tablet\", Price: 300, StockQuantity: 200 }\r\n];<\/pre>\n<p>Here, ProductType is the custom type, and it contains the fields:<\/p>\n<ul>\n<li>ProductID: The unique identifier for each product (Text type).<\/li>\n<li>ProductName: The name of the product (Text type).<\/li>\n<li>Price: The price of the product (Number type).<\/li>\n<li>StockQuantity: The number of items available in stock (Number type).<\/li>\n<\/ul>\n<p><strong>Step 2: Define the UDT Type<\/strong><\/p>\n<p>We can define types for a single product as a special named formula that uses the := assignment operator and <em>Type<\/em> function.<\/p>\n<p><em>ProductType <\/em><em>:=<\/em> <em>Type<\/em><em>(<\/em> <em>{<\/em><em> ProductID: Text<\/em><em>,<\/em><em> ProductName: Text<\/em><em>,<\/em><em> Price: Number<\/em><em>,<\/em><em> StockQuantity: Number <\/em><em>}<\/em> <em>)<\/em><em>;<\/em><\/p>\n<p><strong>Step 3: Using the User-Defined Types inside User-Defined Functions<\/strong><\/p>\n<p>Now that we have a ProductType which is a custom data type, to use this data type we will be creating a <strong>UFD<\/strong> inside which we will be using the product type data type.<\/p>\n<p>Inside the UFD, it will take in a product and calculate its total value based on the stock quantity and price of the product.<\/p>\n<p>Here is the User-defined function:<\/p>\n<p><em>TotalValue<\/em><em>(<\/em><em> Product: ProductType <\/em><em>)<\/em><em>: Number <\/em><em>=<\/em><em> Product.Price <\/em><em>*<\/em><em> Product.StockQuantity;<\/em><\/p>\n<p>This function which is <em>TotalValue<\/em>, takes in a <em>Product<\/em> (<em>data type <\/em><em>ProductType<\/em><em>)<\/em> and returns the total value of that product in stock.<\/p>\n<p>Here is How you could define the data and the custom data type inside the power fx formulas as shown below:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40308\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"1604\" height=\"628\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 1604w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x117.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1024x401.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x301.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-1536x601.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/10User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x258.png 660w\" sizes=\"(max-width: 1604px) 100vw, 1604px\" \/><\/p>\n<p>Let\u2019s say we have a table of products, and we want to calculate the total value of each product in stock. Here\u2019s how we can do it:<\/p>\n<p>TotalValue(First( Products ))<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40309\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/11User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"766\" height=\"319\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/11User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 766w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/11User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x125.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/11User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x275.png 660w\" sizes=\"(max-width: 766px) 100vw, 766px\" \/><\/p>\n<p>Here, we call the <em>TotalValue<\/em> function, passing the first product from the Products table, and then the function calculates and returns the total value (Price * StockQuantity).<\/p>\n<p>We will be calculating the first product and the data inside that product is Price = 1000 and StockQuantity = 50.<\/p>\n<p>As per the <em>TotalValue <\/em>function, It should return the value which is (Price * StockQuantity) i.e: 1000* 50 = 50000 as you can see in the screenshot below.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-40310\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/12User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png\" alt=\"User-Defined Functions and User-Defined Types in Canvas Apps\" width=\"876\" height=\"401\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/12User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps.png 876w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/12User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-300x137.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/12User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-768x352.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/01\/12User-Defined-Functions-and-User-Defined-Types-in-Canvas-Apps-660x302.png 660w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>In this blog, we explored the capabilities of <strong>User-Defined Functions (UDFs)<\/strong> and <strong>User-Defined Types (UDTs)<\/strong> in PowerApps, showcasing how they enable more structured and reusable app logic.<\/p>\n<p>By defining your own data types and leveraging UDFs, you can simplify complex processes, improve maintainability, and enhance the flexibility of your applications. The button-click example shows how you can easily change parameters to create flexible solutions for different needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Building Canvas Apps in PowerApps presents a challenge. Microsoft has provided great built-in functions, but what if your App needed something other than the built-in functions? You would have to create workarounds\u2014repeating formulas, juggling nested logic, and spending extra time managing it all. It worked, but it wasn\u2019t ideal. Now, Microsoft is upgrading the process\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2025\/01\/how-to-use-user-defined-functions-and-user-defined-types-in-canvas-apps\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1954,38,2361],"tags":[1988],"class_list":["post-40298","post","type-post","status-publish","format-standard","hentry","category-canvas-apps","category-microsoft-powerapps","category-technical","tag-canvas-apps"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/40298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=40298"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/40298\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=40298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=40298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=40298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}