Howto Clear a Sort on a Query on VBA? - excel

I have a query on my Excel sheet which is sorted on 2 different columns and I wish to keep it that way because I make searches on data that require this particular order
I noticed that if I manually sort on a column of the sheet, when I refresh the query, the pre-defined order is not reapplied...
And if I remove the sort manually... then the query is well applied and I get the order I wanted
Is this normal behavior ?
I tried to remove on VBA with a Sort.SortFields.Clear... but it didn't remove it and kept the "manual sort".
Is there a way to force the removal of the Sortfields ?
Thanks to all.

Related

Editing data through a filter in Excel

I have a large imported .csv as a (Query) table in an Excel workbook. I'd like for users of the workbook to be able to select a small subset of that data and update some values without having to play around with filters on the table.
To that end, I've set up a FILTER on a separate sheet, something like:
=FILTER(my_table[some_column], my_table[id_column]="some value")
That pulls in values from the relevant column and displays them.
My question: is there any way to allow users to edit the values retrieved with the FILTER, so that the changes are reflected in the original table? Attempting to edit such a value now just edits the underlying field, causing the FILTER to update and display #SPILL! (which makes sense, since there is not enough free space to render the result).
I've looked at options for FILTER, and thought about writing some custom VBA code to do what FILTER does "manually", and then watch the sheet for updates in that range - but that seems like a lot of coding to do something I would imagine is more commonly needed?
Am I going to have to code this up in VBA? Or is there some alternative approach to using the FILTER?

Power query data load into model and table does not sort correctly

I have a table that I fetch via a connect through Power Query, which has a list of names. I apply some steps including sorting the names column alphabetically and then loading it to a Table and the "Data Model". However the table that is loaded onto a worksheet contains the list of the names sorted in a completely different order, its like Excel is ignoring my sorting preference completely. I tried to sort the data in the "Data Model" resorting it in Power query even the table in the worksheet itself, but after I hit refresh it reverts to the wrong order.
Try Table.Buffer wrapped around the sort
= Table.Buffer(Table.Sort(Source,{{"date", Order.Ascending}}))
or, alternatively, add an index at start, and resort on index when done
I can confirm buffering doesn't work. Incredible bug.

How to make a file in Excel, that refreshes from Query Editor and work on it

I am using Power Query Editor to create a working file, using multiple tables from several sources.
After I combine these and make my working file, I am using it to make some work on columns I add later on the working file.
I have noticed that the values I enter in the working file are not bound to the main key, lets assume the first column, but they are independent values in a column.
The result is that if one table changes, for example one line is deleted or I change the sorting of the Query, my working file is wrong, since the data changed but the added columns remain as they were.
Is there a way to have the added columns to be bound with a value, as it is for example with VLOOKUP?
How can I make a file that will update from different sourcesbut stil I can work on it without the risk of misplacing the work I do.
I hope I am clear.
Thank you in advance!
This is fairly simple if each line in your table is unique (which in your example you say the first column can serve as a key). Setup your working columns on the table and then load the table into PQ (as a connection only). Then go to your original query that is combining your data and add a merge at the end where you merge against the table you just loaded into PQ and match on your key. Then expand only your working columns from the merge.
This way whenever you refresh your table, it will match lines against it's existing output in your work before updating, so data in your work columns will be maintained. However note this is only going to retain values, not any formulas you may be using in your work columns.

PowerQuery duplicate rows from external source

I have prepared a master Excel file which pulls data by means of a Power Query from several smaller Excel worksheets, all containing the same set of data (same columns) - one per employee.
Today I noticed that for some employees, some of the data is duplicated in the master table, even though said duplicates do not exist in their separate worksheets.
The master query is made up of separate "Connection Only" queries, pointing to each individual file. Regardless of how many times I click Refresh All, Manage Data Model, the duplicates still stay there.
Has anyone encountered anything similar or would you have any ideas what could be the reason behind this and how to get it sorted out?
Thank you!
You havent really provided enough info about your design, but I'm guessing you are using Merge Query steps to combine the "smaller Excel worksheets" ? If so then the typical issue is that you have not specified the correct columns to match on in the Merge Queries Step definition.
If the combination of columns you have chosen on at least one side of the Merge are not unique, then duplicated rows will appear on the subsequent Expand step.
The way to find these is to start a new Query against each source table in turn, select the columns you are matching on and use Keep Rows / Keep Duplicates. You should see no rows resulting - any rows that do appear are the source of your duplicates.
I usually save such queries and include them in the Refresh as an automated test going forwards. I put them in a separate Query Group e.g. "Tests - should return 0 rows".

Comparison of data in Access

I have written some pretty lengthy VBA code in excel for the comparison of 2 worksheets. My code does the following:
Lets you import 2 sheets for comparison
arranges the columns
removes departments which require different comparisons into a new worksheet
In sheet 1 checks if the id's appear more than once then checks, which row of data to use for comparison based on the latest update, and deletes the old rows
compares the sheets based on the header and then the cell contents as header names are different, for different values it then highlights them red
finally giving me a breakdown per column per department of differences and any id's that are missing
I have now found that my data set is becoming to big and looking to use MS Access, is it possible to copy my VBA code over to access? What do you guys suggest for this?
Any advice would be helpful.
From the nature of your question it sounds like you may not have used a database before. If you were using access, you would need to totally re-write the code using SQL statements. eg An Aggregating SQL SELECT statement to find the most recently updated update and ignore the rest.
You can use conditional formatting in an access form, but it's no better than using it in excel. How many rows does your data have? Will it fit in an excel sheet?
You might use access to pre-process the data to remove the unwanted rows that you use in excel. OR use power query or sql directly from excel to remove them.
You have a way to go.
Harvy

Resources