Index Match or Vlookup in a Power Query - sql

I am trying to build a query that populates data in a column in a similar way to how an index, match or vlookup works.
My workbook has 2 sheets:
Contains open order data pulled from SQL (SQL_Data)
Contains saved comments that were manually entered on the SQL sheet (Preserved_Comments)
I have two queries set up:
Saves the order number and the manually input comments from the SQL_Data sheet, and puts them in a table on the Preserved_Comments Sheet
Refreshes the SQL data table
I have been trying to add a 3rd query that adds the comment column back into the SQL_Data sheet, but I can't figure out how to do a join / index, match / Vlookup that looks at the order numbers and populates the saved comment.
My goal for this is to create an order report where when the SQL data is refreshed, the manually added comments are saved and follow the order number.
Any guidance would be appreciated!

You can merge both Queries into a new one. Use a key column, It would be the lookup array in INDEX/MATCH. This should allow you to join the column.

Related

Update Script to Populate empty fields

I have empty cells in a sql table that I would like to populate at one time. I have an excel spreadsheet with the corresponding numbers that need to go in the empty cells. I would like to take the spreadsheet and use it to populate the empty cells in ssms.
Excel Spreadsheet
Based on what I've read I need to make an update script that will take the spreadsheet and say, "where you find a matching OBJECTID update the number from STAND_OPER_CODE(spreadsheet) to the STAND_OPER_CODE(SSMS)"
SSMS

Populate table using VBA/Formulas

I'm trying to remove manual data entry and duplicate from a process. I have a report that is exported to excel and I'm trying to merge it with a prebuilt data set. I've tried the basic vlookup and if formulas. Where I am running into trouble is Column D lists an activity which may or may not be leave. When it is leave, I need the value returned to Column N and the Row corresponding to date and ID for that employee. Is this something that is even possible?
Sample Data

How to interact between two tables on both directions in Excel?

I have 2 sheets in my Excel project:
In "Sheet1", I have a big data table, with 4 columns:
DataTable[Country], DataTable[Brand], DataTable[Parameter], DataTable[Calculated].
On "Sheet 2" I have a dashboard. I have there a table called FilteredTable that presents the data from DataTable. I have there a drop down command that lets the user select country, and the table is filtered accordingly.
I want that the FilteredTable will not only show data from the original DataTable, but to let the user to change the [Parameter] column. When changing it, I want that the [Calculated] column in both tables will be updated accordingly. If the user will change the country, then the FilteredTable will show the parameter that is stored in DataTable for that combination of [Country] and [Brand]. And if the user will get back to the first country, the displayed parameter will be the last one that the user entered.
I am a bit confused how to do it.
What I have done so far is:
1) to read into FilteredTable rows from DataFilter, using a formula array. I am mirroing this way [country],[brand] and [calculated]
2) in the DataTable[paramter], I read from FilteredTable[parameter] the same way, with a formula array.
It works fine, untill I change a country, and then the parameters in FilteredTable are already do not match the new country, and in DataTable, the parameters for the old country where changed to 0.
I'm in a logical loop. Is there a way out?
Thanks
Have you considered using 3 tables instead of 2? This would be: the original data table, a table which pulls in all values created through manual entry from the display table, and the display table itself.
In VBA, create a function which runs each time a formula is changed in the display table. That function should take the new data from the user, and copy the altered row onto the 'manual entry' table. For the display table itself, you could either recalculate manually through VBA every time a change is made, or have a formula which looks to see whether there is data in the manual table. If there is data in the manual table, that is where the value is pulled from. Otherwise, data is pulled from the original data table.

#REF! result when using INDEX function in Excel

I am trying to create a couple of reports from data on another Excel worksheet based on the value in a drop down list. I am using the MATCH and INDEX functions and have created Named Ranges of the columns of data. I am able to get the first value I want in the report but none of the others, even though when I debug by evaluating the formula it points to the right cell but still displays #REF! instead of the actual value from the referenced cell.
I'll do my best to make this clear:
In "POST_Data" worksheet I have 4 columns titled Course Name, Course Length, Attendee and Date Attended. Currently I have 33 rows of data (plus the header row) but I need the reports to be dynamic since new data will be added from time to time.
I have created Dynamic Named Ranges of the data using the OFFSET function (e.g. for the Course Name data I have a NameRange called CourseNamesData = OFFSET(POST_Data!$A$2,0,0,COUNTA(POST_Data!$A:$A),1)
In the "DashBoard_and_Data Entry" worksheet I have a two report areas: one to report the Course Name and Date Attended for a specified Attendee (specified by a drop down list in cell C7) and the other report to provide the Attendee Name and Date Attended for a specified Course Name (specified by a drop down list in I7).
In row 8 I report the column that the data belongs to in the POST_Data worksheet
What IS working: When I choose an Attendee from the drop down list in C7, I correctly report the first of the Course Names for this attendee from the data in the POST_Data worksheet. I used the following formula to do so: =INDEX(CourseNamesData,MATCH(C7,AttendeeNamesData,0),B$8)
What is NOT working: The corresponding "Date Attended" data when I use a similar formula as the one that is working. I have: =INDEX(DateAttendedData,MATCH(C7,AttendeeNamesData,0),C$8) but this gives me the #REF! error.
Again, when I try to follow the data that this formula points to, it looks like it is pointing to the correct cell but not showing the result.
Another issue is how to get all the data corresponding to the choice in the drop down and not just the first row. So for example, if I choose Richards, K. from the attendee list and he has attended 4 training courses, I need all 4 to show up, not just the first one.
I appreciate any help or insights on this. If you know of a better way to display the workbook contents, please let me know.
Thanks!
Can you provide a screenshot so that I can better understand the issue?
With regard to your post_data worksheet, you might find it easier to turn the data into a table. You can then point your named range to the column within the table without needing to use the offset function, and your range will update automatically as you add to the table.
I have a entire playlist on my youtube channel devoted to using ranges and tables if you are interested. https://www.youtube.com/playlist?list=PL1nLTDk2QLL9415OPSjIICJs1EeV-HeK3

Excel or SQL Server - Multiple columns to rows

In Excel 2010 or Microsoft SQL Server 2012:
I have a table that has an ID in column a, and then columns B through (C - MM) with locations.
I want to have column A be all of the locations & then column B be the ID.
Any way I can figure out so far has been to transpose by hand.
Any help would be greatly appreciated!
Imaged added: image
here's a way that's semi-automatic in Excel which will work assuming the ID row is unique (if it isn't unique, you will need to clean that up first)
Assume your original worksheet of data is named "Raw Data"
Convert the raw data into a Table or Named Range - call it Table1
Add a new worksheet, call it "Normal Data" and type "ID" into cell A1 and "Location" into cell B1
Copy the data (no header) from column A (this is the list of IDs) from "Raw Data" into column A of "Normal Data"
Add this formula to column 2 of "Normal Data" as follows, but change "X" to the number of rows of data (excluding header) you have in "Raw Data":
=VLOOKUP(A2,Table1,ROUNDDOWN((ROW()-2)/X,0)+2,FALSE)
Make sure this looks correct
Append the entire "List of ID's" a few times to column 1 of "Normal Data" a couple of times
Make sure it still looks correct
If your location data extends to Column MN, then you need 350 total copies of the original ID list.
Save the Excel to something like "Normalize Location with Formula"
Save the excel to something like "Normalized Location Data"
Copy paste values of "Normal Data" to save values only, no formulae
Save the worksheet
Optionally filter the "Normal Data" to rows with blank location data and delete
This is now ready to import to a DB (and if you didn't delete the blanks, you cand just delete them via SQL after you import)
Why this works: Vlookup gets the correct row of raw data, and then the formula dynamically adjusts to the correct column based on the row count.
Pivoting rows into columns in SQL Server
Spioter, thanks for the info. I never tried this as i finally found information about using the UNPIVOT command in SQL.
Link is above.