User Profile
ColinJHarrison
Brass Contributor
Joined Oct 03, 2022
User Widgets
Recent Discussions
Re: Getting a table to dynamically match a variable range's row count
Riny_van_Eekelen Right... Hadn't thought of that. Currently I PQ the source data into a hidden sheet, and then use shenanigans like this to generate a range of info sheets that the users want. But I could just compose the user sheets directly with PQ. Hmm... Some of the sheets I need to generate combine info from different PQ imports (so, my FILTER() function might be acting on one source, but my table formulas on a different source...) Can I make a PQ combine data from multiple sources?5.2KViews0likes3CommentsGetting a table to dynamically match a variable range's row count
Hello Excel wizards, I find myself doing something which feels really clunky, and I'm hoping there's a smarter solution. I import a filtered range of values using a FILTER() call (let's say in A2) which will populate columns A2:Bx. The row depth (x) is variable, depending on Power Query updates of the source data that FILTER() is acting on. Next to this data, in C2:Dx (let's say) I want to construct a table that adds new calculations based on the values in the FILTER() range. I'll attach an example workbook. (Why a table? Because it's convenient for formula editing, and this table itself might be referred to in other functions elsewhere...) How can I get the table in C2:Dx to dynamically match the row count (x) of the filtered range in columns A2:Bx? I don't know any way of doing that. You can't use a FILTER() function inside a table (right?)*, which is why I'm just placing my table (C2:Dx) next to the FILTER() output. My "solution" (shown in the attached workbook) is to build a table with about twice as many rows as I anticipate ever needing, and to use some kind of masking formula in the table cells that starts with IF(A2="","", ...) to make sure that the table rows below the FILTER() range don't fill up with #N/A! errors. But this feels like a really dumb solution, and of course if I ever guess wrong, and my FILTER() range is longer than my table, then I get a bunch of values that don't calculate at all. I can tolerate this in something I build for myself, but it's an awful thing to leave in a solution built for a client! I would love a better way of getting my table to dynamically match the row depth of my FILTER() ouput! Or indeed just a better solution to the whole problem! Any ideas? Thanks *Note, in my attached simple example, I am only using FILTER() to zap a column, which I know I could do differently. In the real world this is liable to be an embedded FILTER(FILTER()) call acting on both columns and rows of the source data, so I can't easily see how to make that into a column formula in the table itself, for example...Solved5.8KViews0likes6CommentsRe: Passing a Table as a variable (in a LAMBDA() function)
OK. That makes sense. I guess I was thinking I needed to pass a ref to the actual dynamic range rather than just to its name. But of course that wouldn't make sense for an INDIRECT() call, eh... Hm. In any case, I can see how to make what I'[m trying to do work now, so, once again, thank you for your assistance!5.1KViews0likes2CommentsRe: COUNTIFS problem
Ellbeardo Hi Ellbeardo, If I've understood you correctly, you have a data set like the one I've shown in the attached image (your column T is my column A, and your W is my B), in which Column A contains various values, including "Other" and "Temporary", against which, in column B, there can be various values, but you want to count only the pairs where A= either "Other" or "Temporary" and B=0 (which I have highlighted yellow in the image.) You could do this by summing 2 COUNTIFS() calls like this: =COUNTIFS(A1:A19,"Other",B1:B19,0)+COUNTIFS(A1:A19,"Temporary",B1:B19,0) or like this (same thing really) =SUM(COUNTIFS(A1:A19,"Other",B1:B19,0),COUNTIFS(A1:A19,"Temporary",B1:B19,0)) Hope that helps ๐ Colin1.2KViews1like1CommentRe: Passing a Table as a variable (in a LAMBDA() function)
Riny_van_Eekelen Hi Riny (are you the only person on this forum? Haha) I had tried INDIRECT(), but it doesn't give me the expected result. If I have a table called Table1, and I call =Table1[#Headers], (as I have in cell D10 in the attached image/sheet) then I get the header row values spilling horizontally from D10, as I would expect. I would have thought that calling =LAMBDA(Tn,INDIRECT(Tn&"[#Headers]"))(Table1) should do exactly the same thing, but it doesn't. What I get is a spill range the same dimensions as the whole Table, filled with #REF! errors, which are "Invalid Cell Reference" errors. See the screenshot below, in which D4 contains the LAMBDA() call shown in red in D2. Just in case it was an issue with the LAMBDA() test syntax, I assigned the function to a name (TPX()) in the Name Manager and called it directly from cell G4 (=TPX(Table1)), which as you can see, has exactly the same result. I am perplexed. I have attached the sheet below. Cheers, Colin5KViews0likes4CommentsPassing a Table as a variable (in a LAMBDA() function)
Hi, Why can't I do this (in Excel 356)? I have a table called Table I'm trying to build a LAMBDA() function that will contain something like the following (this is the test syntax...): =LAMBDA(T,T[#Headers])(Table) But the T[#Headers] statement is obviously just flat out illegal, because the editor won't even accept it! ("There is a problem with this formula..."). Why is that? How can I construct a reference to a Table that will allow me to pass the Table as a variable and then grab a range from it? Thanks.Solved6.2KViews1like6CommentsRe: Filtering poorly formatted source data...
Riny_van_Eekelen Hi Riny. I think your solution has shown me the way to solve my problem, so thank you very much! (Again!) One question however - do you write your M code directly, or is everything you've put in this solution achievable using the input wizards provided by Power Query? How for instance did you build your custom column call: = Table.AddColumn(#"Removed columns", "Subsection", each if Text.Contains([Column1], "Region -") then [Column1] else null) At this stage I would have no idea how to hand code someting like that, and I'm just wondering how much of https://learn.microsoft.com/en-us/powerquery-m/understanding-power-query-m-functions I need to be on top of to come up with solutions like this myself... ๐ Cheers2.2KViews0likes1CommentRe: Data Validation drop down list
agkrolak Hi agkrolak, First you will need to create a list of all your Code-Definition pairs. This can be on a separate sheet. Next I would declare each column of that list as a Named Range (call one Codes and the other Definitions). If the list will never change length, you can do this just by selecting the whole range in the column (not the whole column - just the cells that contain data) and typing the new name into the Name Box (I'm assuming you know where that is - if not let me know). If the list will change length, you will need to declare dynamic Named Ranges, using either OFFSET() or INDEX() - here's a great tutorial: https://exceljet.net/glossary/dynamic-named-range Now, for your Code drop-down cell, go to Data/Data Validation, and in the Allow drop-down, select List, then in Source put =Codes. For the Definiton cell, use a lookup function like XLOOKUP(), or INDEX(MATCH()). The function call will be something like this (if your Code drop-down is cell A1). =XLOOKUP(A1,Codes,Definitions,"Code not found",0) The "Code not found" error should actually be completely redundant, because your dropdown list is defined on the same data as the lookup, so in theory it can't fail! But I always like to put in a fail message... force of habit! Hope that works for you! Colin845Views0likes0CommentsFiltering poorly formatted source data...
Hi, I have a weirdly arranged data set that I am importing into Excel via Power Query. My source has the structure I have indicated in the attached example (although the example is greatly simplified), i.e. the columns are divided by sub-headers (highlighted in the example), and the values that I am interested in โ the Regional data โ repeat multiple times in each subsection. What I need are Subsection:Region:Value associations, i.e. 1A : Region1 : Value1 1A : Region2 : Value2 1A : Region3 : Value3 1B : Region1 : Value4 1B : Region2 : Value5 etc. (They don't have to be represented like that neccessarily, but that's the data structure I need). Note that the subsections (1A, 1B, 1C) are not necessarily the same length: some subsections might be missing data on one or more sites, meaning that the row count for each section is unpredictableโฆ (so, I canโt just use Group by number of rows, in the Power Query import, for instance). This could also change between imports, so any solution has to be able to adapt to variable row counts. The way I initially did it was to remove the 2 Site columns altogether in the Power Query import, leaving just Region and RegData, and then just call UNIQUE() on the resulting import table, but that only works if no region has the same value in 2 different subsections, which could happen, and would break downstream calculations if it did (because my UNIQUE() function would return a range missing a row). It would also be a problem if, by chance, one subsection had no values for a particular Region. I need the solution to return a null value in that case (e.g. 1B : Region2 : NULL), or in other words, the solution has to return a 3x3 range, even if some values are empty, and/or some values are the same... I hope that makes sense. Many thanks for any suggestions.Solved2.4KViews0likes6CommentsRe: Manually updating Tables?
Hi again Riny. OK, so I tried setting up a query, and here's the problem I keep hitting with this client. I use their Sharepoint system. I sync files locally, but I am actually working on their system. Nevertheless, when I set up a power query, it only works locally. When someone else accesses the file (which is saved on Sharepoint) and tries to call the refresh function, they get a [Datasource.error] which clearly is looking for a local path ("C:\Users..."). How do I stop that from happening? ๐1.3KViews0likes1CommentRe: Manually updating Tables?
Hi Riny! Yeahhh, I know... In principle... And in the long run that will probably be the solution I work towards, but my desire to provide a slightly more "hands on" solution in the short term is partially a change management thing, partially an issue with network accessibility (for me).1.3KViews0likes0CommentsManually updating Tables?
Hi, I have created a tool to be used by people who are not excel pros. The tool accepts data from 2 or more csv-style reports (output from other programs) and uses it to calculate a data presentation that corresponds to my users' needs. What I want is a painless way for my users get that csv data into the "back end" of the tool I have made for them. Because of how I have set up this tool, the tabs that accept the raw data are formatted as Tables. Problem is, for now, copying the data into these Tables is messy. Each csv report will always have the same column order and header names, but the number of rows in each report will be different every time. Just copying the whole csv report and overwriting the whole table doesn't work, as it deletes the Table, which will break the calculations in the main tab. But any other copy-paste routine is also fraught, (as in the case where the incoming data has less rows, and the result of the copy-paste exercise leaves a few rows of old data at the bottom of the Table...). Also, at least one of these csv reports is liable to have anything up to 5,000 rows. I don't want to require my users to manually select that many rows for copying and pasting if I can avoid it. I'm sure there's a smarter way of doing this, that is easy for my non-technical users. For now, I do not want to get into Power Queries etc. and I can't use VBA (not permitted on my client's system). Users need to be able to update the tool whenever they want to, and need to be able to understand what they are doing. I would appreciate any suggestions. Thanks.Solved1.5KViews0likes4Comments
Recent Blog Articles
No content to show