{"id":2324,"date":"2020-04-05T22:07:41","date_gmt":"2020-04-05T22:07:41","guid":{"rendered":"https:\/\/portfolio.accrualhub.com\/powergi2\/?p=139"},"modified":"2025-09-09T22:07:28","modified_gmt":"2025-09-09T22:07:28","slug":"power-query-files-from-folder-make-the-sample-file-the-one-with-the-most-columns","status":"publish","type":"post","link":"https:\/\/powergi.net\/es\/blog\/power-query-files-from-folder-make-the-sample-file-the-one-with-the-most-columns\/","title":{"rendered":"Power Query Files from Folder:"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"2324\" class=\"elementor elementor-2324\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3454f4bc elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3454f4bc\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-72c6bd37\" data-id=\"72c6bd37\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-24254871 elementor-widget elementor-widget-text-editor\" data-id=\"24254871\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\n<p class=\"wp-block-paragraph\">When we connect to a folder to combine all the files, Power Query creates a \u201cQuery\u201d called \u201cSample File\u201d, which is used as example to process each file, the results will depend on the columns that exist in this file. <strong>But what happens when any of the files have less columns than others?<\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">In the below example, we have three files with 5 columns in common, but there are a couple that are not present in the three files: <em>Contact2, ContactType2 and Address Line 2.<\/em><\/p><div id=\"seology-cta-1\">\t\t<div data-elementor-type=\"section\" data-elementor-id=\"7276\" class=\"elementor elementor-7276\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-7e3f164 e-con-full e-flex e-con e-parent\" data-id=\"7e3f164\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"background_background\":\"classic\",\"jet_parallax_layout_list\":[]}'>\n\t\t<div class=\"elementor-element elementor-element-9078c9f e-con-full e-flex e-con e-child\" data-id=\"9078c9f\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t<div class=\"elementor-element elementor-element-7b99949 elementor-widget elementor-widget-heading\" data-id=\"7b99949\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">From vision to execution<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8e61db5 elementor-widget elementor-widget-heading\" data-id=\"8e61db5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Whether you're just starting or scaling automation, we help turn your ideas into impactful solutions.<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-a578907 e-flex e-con-boxed e-con e-child\" data-id=\"a578907\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e8c827b elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"e8c827b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"#ctc_chat\">\n\t\t\t<i aria-hidden=\"true\" class=\"fab fa-whatsapp\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d834237 elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"d834237\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"https:\/\/powergi.net\/es\/contact\/\">\n\t\t\t<i aria-hidden=\"true\" class=\"far fa-envelope\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<\/div>\n<p>Enhance your business efficiency with our comprehensive <a href=\"https:\/\/powergi.net\/microsoft-power-platform-consulting-services\/\"><strong>Power Platform Consulting services<\/strong><\/a>. Our experts ensure seamless data integration across all files, leveraging Microsoft Power Platform\u2019s capabilities for robust automation and innovative solutions. Whether managing complex datasets or optimizing workflows, our team is dedicated to maximizing your organization\u2019s potential through tailored consulting services.<\/p>\n<p>\u00a0<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-149\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/powergi-image-14864.webp\" alt=\"\"><\/figure>\n\n<p class=\"wp-block-paragraph\">If you open the \u201cSample File\u201d query, and click the \u201cSource\u201d step settings, you will notice Power Query is using the first file as Sample (Option is selected at the moment of combining the files). This is an essential step in any <a href=\"https:\/\/powergi.net\/microsoft-power-platform-consulting-services\/\"><strong>Power Platform consulting service<\/strong><\/a> to ensure seamless data integration.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-145\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-3-1024x194.png\" alt=\"\"><\/figure>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" class=\"wp-image-147\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-5.png\" alt=\"\" width=\"276\" height=\"167\">\n<figcaption>Option selected at the moment of combining the files<\/figcaption>\n<\/figure>\n<\/div>\n\n<p class=\"wp-block-paragraph\">If Power Query uses the workbook with less columns (in this example, Book3.xlsx) as sample file, it will exclude all the columns in Book2 not present in Book3, to avoid this, we should make sure the correct workbook is used as the Sample.<\/p><div id=\"seology-cta-2\">\t\t<div data-elementor-type=\"section\" data-elementor-id=\"7280\" class=\"elementor elementor-7280\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-7e3f164 e-con-full e-flex e-con e-parent\" data-id=\"7e3f164\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"background_background\":\"classic\",\"jet_parallax_layout_list\":[]}'>\n\t\t<div class=\"elementor-element elementor-element-9078c9f e-con-full e-flex e-con e-child\" data-id=\"9078c9f\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t<div class=\"elementor-element elementor-element-7b99949 elementor-widget elementor-widget-heading\" data-id=\"7b99949\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Automate tasks that slow you down<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8e61db5 elementor-widget elementor-widget-heading\" data-id=\"8e61db5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Free up your team\u2019s time and focus on strategic work with digital and robotic automation.<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-a578907 e-flex e-con-boxed e-con e-child\" data-id=\"a578907\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e8c827b elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"e8c827b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"#ctc_chat\">\n\t\t\t<i aria-hidden=\"true\" class=\"fab fa-whatsapp\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d834237 elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"d834237\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"https:\/\/powergi.net\/es\/contact\/\">\n\t\t\t<i aria-hidden=\"true\" class=\"far fa-envelope\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<\/div>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-151\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/image-7-1024x254-1.webp\" alt=\"\">\n<figcaption><br>Contact2, ContactType2 and Address Line 2 are now missing from the resulting table<\/figcaption>\n<\/figure>\n\n<h2 class=\"wp-block-heading\"><strong>Making the sample file the one with the highest number of columns<\/strong><\/h2>\n\n<ol class=\"wp-block-list\">\n<li>Duplicate the query that combines all the files<\/li>\n<\/ol>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-153\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/powergi-image-14918.webp\" alt=\"\" width=\"272\" height=\"324\"><\/figure>\n<\/div>\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>Rename the query to \u201cColumn Count\u201d, then in this new query go to the step \u201c<strong>Renamed Columns<\/strong>\u201d, after the \u201cInvoke Custom Function1\u201d step, and click on \u201cDelete Until End\u201d.<\/li>\n<\/ol>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-156\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-10-1024x348.png\" alt=\"\"><\/figure>\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>Go to the last column in this new query and you will see a column that contains the table in each file. We need to know the number of columns each of the tables have.<\/li>\n<\/ol>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-157\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-11-1024x309.png\" alt=\"\"><\/figure>\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li>Go to tab Add Column and click on Custom Function.\u00a0 Indicate the column name and write <strong>Table.ColumnCount([Transform File])<\/strong> \u2013 (you need to the reference the column that has the table records as shown above, make sure you check the name). Then click <strong>OK<\/strong>.<\/li>\n<\/ol>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-158\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/image-12-1024x648-1.webp\" alt=\"\"><\/figure>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" class=\"wp-image-159\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-13.png\" alt=\"\">\n<figcaption>This should be the result<\/figcaption>\n<\/figure>\n<\/div>\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li>Go to \u201cSample file\u201d, in that query we\u2019re going to insert a step after \u201cSource\u201d and before \u201cNavigation\u201d, select the \u201c<strong>Source<\/strong> step\u201d and then click on \u201cMerge Queries\u201d.<\/li>\n<\/ol>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-161\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-14-1024x197.png\" alt=\"\"><\/figure>\n\n<ol class=\"wp-block-list\" start=\"6\">\n<li>Select the <strong>Column Count <\/strong>query in the second table dropdown and use the <strong>File Name<\/strong> as matching columns. Then hit <strong>OK<\/strong>.<\/li>\n<\/ol>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-162\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/powergi-image-14856.webp\" alt=\"\"><\/figure>\n\n<ol class=\"wp-block-list\" start=\"7\">\n<li>Expand the new column, and select the \u201cCount\u201d field, click OK<\/li>\n<\/ol>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" class=\"wp-image-163\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/powergi-image-14902.webp\" alt=\"\" width=\"342\" height=\"362\"><\/figure>\n<\/div>\n\n<ol class=\"wp-block-list\" start=\"8\">\n<li>Now that the column count per file is available in the \u201cSample File\u201d query just sort the column to have the file with the highest count first.<\/li>\n<\/ol>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-164\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2020\/04\/image-17.png\" alt=\"\" width=\"381\" height=\"371\"><\/figure>\n<\/div>\n\n<p class=\"wp-block-paragraph\">With this workaround you can be sure that Power Query will always use the correct file as sample, regardless of the name of the file.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-165\" src=\"https:\/\/powergi.net\/wp-content\/uploads\/2026\/07\/image-18-1024x367-1.webp\" alt=\"\"><\/figure>\n\n<p class=\"wp-block-paragraph\">Table column count function: <a href=\"https:\/\/learn.microsoft.com\/en-us\/powerquery-m\/table-columncount\" target=\"_blank\" rel=\"noopener\">https:\/\/learn.microsoft.com\/en-us\/powerquery-m\/table-columncount<\/a><\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>When we connect to a folder to combine all the files, Power Query creates a \u201cQuery\u201d called \u201cSample File\u201d, which is used as example to process each file, the results will depend on the columns that exist in this file. But what happens when any of the files have less columns than others? In the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2612,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"glossary_letter":"","footnotes":""},"categories":[35,29,25],"tags":[13,24,16,19],"class_list":["post-2324","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-excel","category-power-bi-cat","category-power-query-cat","tag-automation","tag-data-transformation","tag-excel","tag-power-query"],"glossary_letter":null,"rank_math_title":null,"rank_math_description":"Advanced Power Query tips: Learn to combine folder files by selecting the sample with the most columns. Technical guide on the Power GI blog.","rank_math_focus_keyword":null,"_links":{"self":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts\/2324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/comments?post=2324"}],"version-history":[{"count":0,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts\/2324\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/media\/2612"}],"wp:attachment":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/media?parent=2324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/categories?post=2324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/tags?post=2324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}