• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Returning Table Headers when using Filter Function|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Returning Table Headers when using Filter Function|General Excel Questions & Answers|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Returning Table Headers when using …
sp_PrintTopic sp_TopicIcon
Returning Table Headers when using Filter Function
Avatar
Peter Lewis

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
November 5, 2021
sp_UserOfflineSmall Offline
1
February 22, 2022 - 5:54 am
sp_Permalink sp_Print

I'm using the Filter function to select some data from a table, but whilst it returns the data just fine, I cannot get it to return the table headers.

I recall seeing some shortcut to do this (although it may have been on a different Dynamic Array function)

Can anyone enlighten me as to the correct syntax?

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4449
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
February 22, 2022 - 9:36 am
sp_Permalink sp_Print

Hi Peter,

The FILTER function doesn't return headers, as you've discovered. You would need to use a different formula for this e.g.:

=Table1[#Headers]

This will spill the headers where you want them.

Mynda

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 622
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
3
February 22, 2022 - 7:47 pm
sp_Permalink sp_Print

The FILTER function will return headers (they are just data as far as it's concerned) but only if they are part of the data range you specify and if they match your criteria. Since that last part is rarely true, you tend not to get the headers back. 😉

You can make it true of course by adding something appropriate to the filter criteria but it's usually easier to return them separately as Mynda suggested.

Avatar
NoFT
UK

New Member
Members
Level 0
Forum Posts: 1
Member Since:
August 19, 2022
sp_UserOfflineSmall Offline
4
August 19, 2022 - 11:13 pm
sp_Permalink sp_Print

This seems to work:

=FILTER(Table1[#All],Table1[#Headers]="<column-name>")

To get multiple results

=FILTER(Table1[#All],(Table1[#Headers]="<column-name>")+Table1[#Headers]="<column-name2>")

To get one of the columns from a multiple returned list, e.g. if the 2 above are returned to H1

=INDEX(H1#,,2)

Seems tricky to use the returned values in VLOOKUP/XLOOKUP though (as a spill range)...Confused but might just be a case of getting the references correct.

Avatar
Duncan Williamson
Member
Members
Level 0
Forum Posts: 11
Member Since:
December 23, 2020
sp_UserOfflineSmall Offline
5
October 28, 2022 - 5:28 pm
sp_Permalink sp_Print

There is a fairly easy to use solution to this problem.

Create your worksheet as you have done so far and then add the column headers to your FILTER() output.

Put a number 1 in the cell immediately above every column in your input database to nominate the columns for which you want to see a header and leave the other cells blank. Actually, it doesn't have to be 1, it could be any value but why not keep it simple! Please note, it makes sense to put 1 in the columns that are going to be returned by your original FILTER() function.

Now, put your cursor in the left most cell of the range where you want to headers to appear and enter this: =FILTER(A9:G9, A8:G8) and press enter, where row 9 contains your database headers and row 8 contains your chosen columns.

My screenshot shows how I just did this to answer a question from another forum and it also illustrates one way of suppressing the zeroes that can appear with the FILTER() function. I show the solution with and without zero suppression!

Best wishesquora_filter_chosen_subjects_1.jpgImage Enlarger

Duncan

sp_PlupAttachments Attachments
  • sp_PlupImage quora_filter_chosen_subjects_1.jpg (44 KB)
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4449
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
6
October 28, 2022 - 9:07 pm
sp_Permalink sp_Print

Now that we have the VSTACK function we can return headers like so:

=VSTACK({"Header1","Header2","Header3"...},FILTER(....your filter formula))

There are proper examples in the VSTACK function tutorial here.

Mynda

Avatar
Duncan Williamson
Member
Members
Level 0
Forum Posts: 11
Member Since:
December 23, 2020
sp_UserOfflineSmall Offline
7
October 29, 2022 - 12:09 am
sp_Permalink sp_Print

I don't wish to sound patronising in any way but that is something I hadn't thought of, Mynda, using VSTACK() Append the headers to the FILTER() output.

I worked on it to make sure I could do it and I did it and I know it's not part of the OP's question but I'd like to add that I found I still had to wrap around FILTER(...) if I wanted to return just the columns that meet any criteria I might set. In my example, I only need to see the three columns, Name, Maths and Statistics ... 

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Alexandra Radu
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27276

 

Member Stats:
Guest Posters: 49
Members: 31903
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.