{"id":32945,"date":"2022-10-29T17:20:13","date_gmt":"2022-10-29T11:50:13","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=32945"},"modified":"2022-11-02T17:17:09","modified_gmt":"2022-11-02T11:47:09","slug":"how-to-use-firstn-lastn-and-index-functions-in-canvas-apps-power-fx-on-power-platform","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/10\/how-to-use-firstn-lastn-and-index-functions-in-canvas-apps-power-fx-on-power-platform\/","title":{"rendered":"How to use FirstN(), LastN(), and Index() functions In Canvas Apps (Power Fx) on Power Platform"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>In today\u2019s blog, we will explore how to implement FirstN(), LastN(), and Index() functions for filtering records of the Data Table in the Canvas App.<br \/>\nWe had a client requirement where we needed to find out the top three highest Annual Revenue customers and bottom three lowest Annual Revenue customers for boosting their business.<br \/>\nTo achieve the above requirement, we used Canvas App. Please find the below steps that we used to get the desired results:<\/p>\n<p><strong>Step 1:<\/strong><\/p>\n<p>We created a default Canvas App and in that, we added a DataTable. After creating the data table, we added the Client custom table in it which contains customer details such as Name, and Annual Revenue. As seen in the below screenshot. Also, we sorted the data in descending order based on annual revenue using the Sort function. Please find the below Power Fx formula that we used to sort the Data Table:<\/p>\n<p><strong>Sort(Clients, Revenue, Descending)<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32947\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Power-Fx-1.jpeg\" alt=\"Power Fx\" width=\"1377\" height=\"582\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Power-Fx-1.jpeg 1377w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Power-Fx-1-300x127.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Power-Fx-1-1024x433.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Power-Fx-1-768x325.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Power-Fx-1-660x279.jpeg 660w\" sizes=\"(max-width: 1377px) 100vw, 1377px\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32948\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Power-Fx-1.jpeg\" alt=\"Power Fx\" width=\"1366\" height=\"598\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Power-Fx-1.jpeg 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Power-Fx-1-300x131.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Power-Fx-1-1024x448.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Power-Fx-1-768x336.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Power-Fx-1-660x289.jpeg 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>Step 2:<\/strong><br \/>\nAfter sorting the data table by annual revenue, we performed the below operation:<br \/>\n<strong>1. FirstN()<\/strong><br \/>\nThe FirstN() function returns the first N set of records of a data table.<br \/>\n<strong>Syntax:<\/strong><br \/>\n<em><strong>FirstN(TABLE_NAME,NUMBER_OF_RECORDS)<\/strong><\/em><br \/>\nWhere,<br \/>\nTABLE_NAME: Table name is specified on which we perform the operation<br \/>\nNUMBER_OF_RECORDS: Numeric number which specified how many rows we want to retrieve from the data table.<br \/>\nIn our case, we want to retrieve the Top three customers which have the highest annual revenue. So, we create the Power Fx formula as below:<br \/>\n<strong>FirstN(Clients,3)<\/strong><br \/>\nAfter applying the Power Fx formula, we will get the below result in the data table. You can see the top three customers which have highest annual revenue displayed in the screenshot:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32949\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/3Power-Fx-1.jpeg\" alt=\"Power Fx\" width=\"1366\" height=\"631\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/3Power-Fx-1.jpeg 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/3Power-Fx-1-300x139.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/3Power-Fx-1-1024x473.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/3Power-Fx-1-768x355.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/3Power-Fx-1-660x305.jpeg 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>2. LastN()<\/strong><br \/>\nThe LastN() function returns the last N set of records of a table<br \/>\n<strong>Syntax-<\/strong><br \/>\n<em><strong>LastN(TABLE_NAME,NUMBER_OF_RECORDS)<\/strong><\/em><br \/>\nIn our case, we want to retrieve the Last three customers which have the lowest Annual revenue. So, we create the Power Fx formula as below:<br \/>\n<strong>LastN(Clients,3)<\/strong><br \/>\nAfter applying the Power Fx formula, we will get the below result in the data table. You can see the lowest three customers having the lowest annual revenue displayed in the screenshot:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32950\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/4Power-Fx-1.jpeg\" alt=\"Power Fx\" width=\"1366\" height=\"628\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/4Power-Fx-1.jpeg 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/4Power-Fx-1-300x138.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/4Power-Fx-1-1024x471.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/4Power-Fx-1-768x353.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/4Power-Fx-1-660x303.jpeg 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p><strong>3. Index()<\/strong><br \/>\nThe Index function returns a single record of a data table based on its ordered position in the table.<br \/>\n<strong>Syntax:<\/strong><br \/>\n<em><strong>Index(TABLE_NAME,NUMBER_OF_RECORDS)<\/strong><\/em><br \/>\nExample:<br \/>\n<strong>Index(Clients,3)<\/strong><br \/>\nOutput-<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32951\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/5Power-Fx-1.jpeg\" alt=\"Power Fx\" width=\"1366\" height=\"626\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/5Power-Fx-1.jpeg 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/5Power-Fx-1-300x137.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/5Power-Fx-1-1024x469.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/5Power-Fx-1-768x352.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/5Power-Fx-1-660x302.jpeg 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>In this way, using FirstN(), LastN() ,and Index() function we can easily filter the data table in Canvas App.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/user-adoption-monitor-in-dynamics-crm\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone size-full wp-image-32952\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/User-Adoption-Monitor.png\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/User-Adoption-Monitor.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/User-Adoption-Monitor-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/User-Adoption-Monitor-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/User-Adoption-Monitor-660x165.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In today\u2019s blog, we will explore how to implement FirstN(), LastN(), and Index() functions for filtering records of the Data Table in the Canvas App. We had a client requirement where we needed to find out the top three highest Annual Revenue customers and bottom three lowest Annual Revenue customers for boosting their business.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/10\/how-to-use-firstn-lastn-and-index-functions-in-canvas-apps-power-fx-on-power-platform\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"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":[2361],"tags":[1988],"class_list":["post-32945","post","type-post","status-publish","format-standard","hentry","category-technical","tag-canvas-apps"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/32945","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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=32945"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/32945\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=32945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=32945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=32945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}