Is it possible to get a data from an excel file from a particular table if I have two tables in one worksheet using EPPlus? - epplus

I have a file that contains a few tables on one worksheet. How do I get data from a particular table using EPPlus? thanks a lot
I looked through samples and questions on stackoverflow

You can reference tables by index or by name using this:
var x = new OfficeOpenXml.ExcelPackage(new FileInfo(#"c:\FooFolder\Bin_Template.xlsx"));
var table = x.Workbook.Worksheets[1].Tables["Table1"];

Related

Index Match or Vlookup in a Power Query

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.

Reading xlsx into R and creating new header

I'm a newbie to R.
I read in an Excel file for a survey, but I started reading observations from the 3rd row of the excel file, as the survey download creates a first two rows of the question string (first row for all questions) followed by a second row of multiple choice questions (each option gets its own column except the first option, which is listed in the same column in the second row as the question in the first row).
So now, my dataframe starts with Row 3.
But now I need to create custom variable names - ie. new variable names for each column before I manipulate further. I'm looking for tips on how to best accomplish this.
What I am thinking:
Create an Excel file with the variable names, and then use this is as the header. I'm not quite sure which code I would use to do this.
Code the names as an empty dataframe, and then somehow merge this so the empty dataframe column names are the column names for the file I imported.
I would appreciate some suggestions on how best to do this!

Searching for value in a linked table in power pivot

I have a PowerPivot table that has a column of IDs and a linked table that contains a set of specific IDs that I want to use to create an indicator variable which I can use to sort on in existing tables and charts. Essentially I want:
If the value in column EpisodeID is found anywhere in LostEpisodes[LostID], then return the value "1", otherwise "0".
LostEpisodes is the linked table and LostID is the column that contains the subset of IDs I want to be able to sort on.
I have tried using =IF(VALUES(LostEpisodes[LostID])=[EpisodeID],1,0) but got an error. Is my syntax wrong or should I be using a different approach? Seems simple enough, but I am new to PowerPivot and DAX.
Thanks
OK - So I have found an answer that works and wanted to share. Others may have more elegant solutions, but this worked. This is where I miss MATCH.
I have a linked table called LostEpisodes which contains 2 columns, EpisodeID and Lost (all contain the value of 1 as they are all lost episodes). For my purposes I am manually entering the episode IDs as there are only a few. EpisodeID is also in the main table and is the column I am matching on.
I started with one new column labeled LostLookup with the following formula:
=LOOKUPVALUE(LostEpisodes[Lost],LostEpisodes[EpisodeID],[EpisodeID])
I then created a new column with the following formula:
=if(ISBLANK([LostLookup]),"NotLost","Lost")
This creates the indicator variable I can now use in pivot tables and charts. I have tested it and it works great.
Hope this makes sense!

Copy SQL column from one to another maintaining ID

I am looking to copy SQL long binary data from the "photo" column to the "id_photo_c" column. Both columns are in separate tables. A got a query to show exactly what I need, but unfortunately you cannot copy & paste outputs from the "Results Pane" of mssql.
I cannot copy the entire table from one to another, the new database has more rows (including some duplicates).
http://i.imgur.com/tmRpMh2.png
Here is the code:
SELECT
[GroupTables].[dbo].[VisitorsAdvanced].[RecordNumber], [
GroupTables].[dbo].[VisitorsAdvanced].[photo],
[SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c],
[SugarCRM].[dbo].[contacts_cstm].[id_photo_c]
FROM
[GroupTables].[dbo].[VisitorsAdvanced], SugarCRM].[dbo].[contacts_cstm]
WHERE
[GroupTables].[dbo].[VisitorsAdvanced].[RecordNumber] = [SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c];
It seems like such a simple task (would take two clicks in Excel) - but I can't seem to get it to work.
This isn't a duplicate question. I've seen similar questions on here, none of which describe how to simply copy data from one column to another.
Thank you.
Unless I'm missing something here, it seems like a simple update statement is all you need:
UPDATE [SugarCRM].[dbo].[contacts_cstm]
SET [id_photo_c] = [SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c]
FROM
[GroupTables].[dbo].[VisitorsAdvanced]
INNER JOIN [SugarCRM].[dbo].[contacts_cstm]
ON
[GroupTables].[dbo].[VisitorsAdvanced].[RecordNumber] = [SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c];
Isn't this as straight-forward as updating the data in the contacts_cstm table?
UPDATE contacts_cstm
SET id_photo_c = photo
FROM VisitorsAdvanced
WHERE RecordNumber = xxx_id_number_c

Dynamic Length Excel Tables with Formatting Driven from Dynamic Source Tables

My current setup:
Users need to create reports in Excel which can contain various components like tables, charts etc. These report components are driven off large source tables which are provided to the workbook via a web service. Each source table lives on its own worksheet and the report components live on a separate sheet called "front_sheet".
A greatly simplified example is as follows:
On "input_sheet_1" there is a table which looks like so
The user would then like to create two tables for the report (on "front_sheet") which reference the table on input_sheet_1, that look like this:
These "output" tables contain columns which aren't on the source table (Total Spend) but they may contain more columns such as "Price in euros" where the "price" column is multiplied by some constant.
The table rows are also colour coordinated by their Category. Also there is a "Total" at the bottom of the output tables.
This is easy to do when the input table is static. However I do not know how to deal with this when the input table has a variable number of rows i.e. each time the workbook is refreshed the basket will have different numbers of different items.
Does anyone know how I can achieve this? A requirement is that the user setting up the report does not have to write any VBA at all.
Thanks for taking the time to read this.