{"id":52685,"date":"2025-03-12T14:00:00","date_gmt":"2025-03-12T13:00:00","guid":{"rendered":"https:\/\/blog.sheetgo.com\/?p=52685"},"modified":"2025-06-03T22:07:07","modified_gmt":"2025-06-03T20:07:07","slug":"criacao-de-resultados-no-google-sheets-com-mapa-e-lambda","status":"publish","type":"post","link":"https:\/\/www.sheetgo.com\/pt\/blog\/google-sheets-formulas\/crafting-dresults-in-google-sheets-with-map-and-lambda\/","title":{"rendered":"Cria\u00e7\u00e3o de resultados 2D din\u00e2micos no Planilhas Google com as fun\u00e7\u00f5es MAP e LAMBDA"},"content":{"rendered":"\n[et_pb_section fb_built=&#8221;1&#8243; theme_builder_area=&#8221;post_content&#8221; _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221;][et_pb_row _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; theme_builder_area=&#8221;post_content&#8221;][et_pb_column _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; type=&#8221;4_4&#8243; theme_builder_area=&#8221;post_content&#8221;][et_pb_text _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; theme_builder_area=&#8221;post_content&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;]<blockquote>\n<p><strong data-start=\"47\" data-end=\"56\">Note:<\/strong> This post was originally published in our community forum.<\/p>\n<\/blockquote>\n<p>Google Sheets offers a robust set of features that allow users to handle data dynamically and efficiently. With the addition of LAMBDA and MAP functions, you can simplify complex operations into single-cell formulas that dynamically generate two-dimensional (2D) results. In this blog, we\u2019ll explore how to leverage these functions using a practical example from a product tracking scenario.<\/p>\n<h2>Scenario Overview<\/h2>\n<p>Imagine you are tracking the prices of various products over several months. Your dataset records product details and price updates at different times. The challenge is to summarize the monthly price updates for each product into a single summary table, displaying the latest price of each product by the end of each month.<\/p>\n<h2>Data Structure<\/h2>\n<p>Our main dataset, named `Product`, is formatted as follows:<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/J1VXuU6.png\" rel=\"ugc noopener nofollow\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/J1VXuU6.png\" title=\"\" alt=\"\" \/><\/a><\/p>\n<h2>Objective<\/h2>\n<p>The objective is to create a `Monthly Product Summary` table that dynamically updates to show the latest price of each product by the end of each month. This table should adapt to new data as it\u2019s added to the `Product` tab.<\/p>\n<h2>Step-by-Step Implementation<\/h2>\n<h3>1. Setting Up Date Headers<\/h3>\n<p>First, we generate the headers for each month in the summary table:<\/p>\n<p><strong>Cell B1:<\/strong><\/p>\n<pre><code data-highlighted=\"yes\" class=\"hljs language-swift\"><span class=\"hljs-operator\">=<\/span><span class=\"hljs-type\">ARRAYFORMULA<\/span>(<span class=\"hljs-type\">IF<\/span>(<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$2<\/span><span class=\"hljs-operator\">=<\/span><span class=\"hljs-string\">\"\"<\/span>, <span class=\"hljs-string\">\"\"<\/span>, <span class=\"hljs-type\">TEXT<\/span>(<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$2<\/span>,<span class=\"hljs-string\">\"yy\"<\/span>)<span class=\"hljs-operator\">&amp;<\/span><span class=\"hljs-string\">\"-\"<\/span><span class=\"hljs-operator\">&amp;<\/span><span class=\"hljs-type\">TEXT<\/span>(<span class=\"hljs-type\">MONTH<\/span>(<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$2<\/span>),<span class=\"hljs-string\">\"00\"<\/span>)))<\/code><\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/K9cqgCP.png\" rel=\"ugc noopener nofollow\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/K9cqgCP.png\" title=\"\" alt=\"\" \/><\/a><\/p>\n<p>This formula uses `ARRAYFORMULA` to apply text formatting across each date in row 2, creating a YY-MM format for month headers.<\/p>\n<h3>2. Generating Monthly Date Ranges<\/h3>\n<p>Next, we prepare a list of end-of-month dates for each month within our desired range:<\/p>\n<p><strong>Cell C2:<\/strong><\/p>\n<pre><code data-highlighted=\"yes\" class=\"hljs language-swift\"><span class=\"hljs-operator\">=<\/span><span class=\"hljs-type\">ARRAYFORMULA<\/span>(<span class=\"hljs-type\">EOMONTH<\/span>(<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>,<span class=\"hljs-type\">SEQUENCE<\/span>(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">15<\/span><span class=\"hljs-operator\">+<\/span><span class=\"hljs-number\">12<\/span>,<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">1<\/span>)))<\/code><\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/juntNTA.png\" rel=\"ugc noopener nofollow\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/juntNTA.png\" title=\"\" alt=\"\" \/><\/a><\/p>\n<p>Here, `EOMONTH` and `SEQUENCE` generate end-of-month dates starting from the date in `B2`, covering a range of potentially 27 months (15 + 12 as an example).<\/p>\n<h3>3. Listing Unique Products<\/h3>\n<p>We identify all unique products from the `Product` tab:<\/p>\n<p><strong>Cell A4:<\/strong><\/p>\n<pre><code data-highlighted=\"yes\" class=\"hljs language-swift\"><span class=\"hljs-operator\">=<\/span><span class=\"hljs-type\">UNIQUE<\/span>(<span class=\"hljs-type\">Product<\/span>!<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$B<\/span>)<\/code><\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/G43ff0m.png\" rel=\"ugc noopener nofollow\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/G43ff0m.png\" title=\"\" alt=\"\" \/><\/a><\/p>\n<h3>4. Dynamic Price Mapping<\/h3>\n<p>The most complex part is creating a dynamic summary of prices. This involves mapping over the list of products and, for each product, mapping over the list of months to fetch the latest price by the end of each month:<\/p>\n<p><strong>Cell B4:<\/strong><\/p>\n<pre><code data-highlighted=\"yes\" class=\"hljs language-swift\"><span class=\"hljs-operator\">=<\/span><span class=\"hljs-type\">MAP<\/span>(<span class=\"hljs-variable\">$A<\/span><span class=\"hljs-variable\">$4<\/span>:<span class=\"hljs-variable\">$A<\/span>, <span class=\"hljs-type\">LAMBDA<\/span>(product,\n  <span class=\"hljs-type\">IF<\/span>(product<span class=\"hljs-operator\">=<\/span><span class=\"hljs-string\">\"\"<\/span>,<span class=\"hljs-string\">\"\"<\/span>, \n    <span class=\"hljs-type\">MAP<\/span>(<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$1<\/span>:<span class=\"hljs-variable\">$1<\/span>, <span class=\"hljs-type\">LAMBDA<\/span>(month, \n      <span class=\"hljs-type\">IF<\/span>(month<span class=\"hljs-operator\">=<\/span><span class=\"hljs-string\">\"\"<\/span>, <span class=\"hljs-string\">\"\"<\/span>, <span class=\"hljs-type\">IFNA<\/span>(<span class=\"hljs-type\">QUERY<\/span>(<span class=\"hljs-type\">FILTER<\/span>(<span class=\"hljs-type\">Product<\/span>!<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$D<\/span>, <span class=\"hljs-type\">TEXT<\/span>(<span class=\"hljs-type\">Product<\/span>!<span class=\"hljs-variable\">$D<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$D<\/span>,<span class=\"hljs-string\">\"YY-MM\"<\/span>)<span class=\"hljs-operator\">=<\/span>month, <span class=\"hljs-type\">Product<\/span>!<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-variable\">$2<\/span>:<span class=\"hljs-variable\">$B<\/span><span class=\"hljs-operator\">=<\/span>product),<span class=\"hljs-string\">\"SELECT Col2 ORDER BY Col3 DESC LIMIT 1\"<\/span>),)\n      )\n    ))\n  )\n))<\/code><\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/aRF779E.png\" rel=\"ugc noopener nofollow\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/aRF779Eh.png\" title=\"\" alt=\"\" \/><\/a><\/p>\n<p>This formula maps over each product, then maps over each month. It uses `FILTER` to narrow down records to the specific product and month, then `QUERY` to fetch the latest price for that month using the timestamp (`ORDER BY Col3 DESC LIMIT 1`).<\/p>\n<h2>Conclusion<\/h2>\n<p>By integrating `MAP` and `LAMBDA` with other Google Sheets functions, we\u2019ve created a dynamic, easily updatable summary table that adapts as new data is added. This approach minimizes the need for manual updates and allows for extensive scalability in managing product data over time. This is just one example of how powerful these functions can be in transforming your data handling and analysis in Google Sheets.<\/p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]\n","protected":false},"excerpt":{"rendered":"<p>Note: This post was originally published in our community forum. Google Sheets offers a robust set of features that allow users to handle data dynamically and efficiently. With the addition of LAMBDA and MAP functions, you can simplify complex operations into single-cell formulas that dynamically generate two-dimensional (2D) results. In this blog, we\u2019ll explore how [&hellip;]<\/p>\n","protected":false},"author":49,"featured_media":44470,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[54],"tags":[],"class_list":["post-52685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-google-sheets-formulas"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/posts\/52685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/comments?post=52685"}],"version-history":[{"count":0,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/posts\/52685\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/media\/44470"}],"wp:attachment":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/media?parent=52685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/categories?post=52685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/tags?post=52685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}