SSAS (2008R2) & Excel Filter Issue When Refreshing Data - sql-server

We have an instance of 2008 R2 which is running approx 6 cubes. The situation I am finding is as follows.
A user connects to the cube via MS Excel 2010 using the normal Data Sources method.
Lets say they create a very simple pivot table...Accounts on the rows & Months on the columns with a measure giving us the total value for each Account. At the time of the user creating the report there were 11 months of data in available in the cube (Jan > Nov) so the pivot table reflects this in Excel. The user has applies a few filters (say 5) on the row to select some Accounts ad hoc. The user then saves this file to his desktop and leaves it until Decembers data has become available in the cube. December is upon us and we refresh the cube so that it now contains Decembers data as well. The user reopens the Excel file and right clicks on the pivot and refreshes the data with the expectation of seeing a full years data for the five account selected but this is not the case. What in actual fact happens is that all the data which is there before is lost and the pivot table is completely blank. Can anyone help with why this is happening and a potential solution?
I have an idea in my mind that Excel is storing the accounts being filtered using some unique identifier and when the cube is reprocessed for the new month new unique IDs are being assigned to the accounts and therefore a match is not happening. There must be a work around to this as otherwise every report which is generated is effectively a throw away effort. Cheers!

In my case this indeed was caused by the poor cube design: the generated MDX referenced an ID that changed every time the cube was rebuilt:
WHERE [Log Author].[PM PRIMARYKEY].&[29872574],
I agree the best way to fix this is to change the ETL.
PS The way I viewed the generated MDX (thanks to Marco Russo) was by selecting the pivot and then running this macro (open VBA, paste it, hit F5):
Sub DisplayMDX()
Dim mdxQuery As String
Dim pvt As PivotTable
Dim ws As Worksheet
Set pvt = ActiveCell.PivotTable
mdxQuery = pvt.MDX
' Add a new worksheet.
Set ws = Worksheets.Add
ws.Range("A1") = mdxQuery
End Sub

Related

SSIS - Excel to SQL Server with changing column names

I have an Excel sheet that changes column names based on the year and current week of the year, so for example 201901 would be the first week of 2019.
The Excel sheet that is sent to us daily automatically adjusts the column names based on the current date (up to 6 months), so currently (31/07/2019) the year and week show 201931 - 202011:
So the N column next week will be 201932 (the columns shift left basically).
I have tried changing the Excel source columns to a different alias of just 1,2,3,4 etc in hopes to just get the data into SQL Server, and then script a trigger in SQL Server to change column names but doesn't work due to the mapping SSIS requires.
Works fine until the column changes to next week.
A simple method would be to drop the table and just dump the file in a new table named the same but can't see how to set up in SSIS as you need to map the column names (which unfortunately change).
Here is how the dataflow looks:
Ideally, for me, something like this would be perfect:
But not sure how to achieve this outcome in SSIS?
I would suggest transforming the data. Currently, you have a "cross-table"-format.
How about putting the Excel data in the form of (RAG_week; CalenderWeek; Value_of_CalenderWeek) ? For doing this you can use an Excel-Macro which fills a new Sheet in the Excel file. (Each cell is transformed in one dataset, being a row on its own.) Next, you create a similar table on the SQL Server. Then you can create a SSIS package with constant column assignment, simply appending the new data each week.
This impacts the further evaluation of your data, but seems to be a far more stable approach.

How to copy a record from Excel and paste into SSMS V 17 to update existing record

Folks,
I am a novice, really a business user (not techie), in SSMS v 17. I used to update a MS Sql Server database in Azure using Excel add-in (Devart), but then Active Directory Multifactor Authentication was introduced at the organization and I cannot use Devart any longer. I am forced to use SSMS v 17.5 to make updates to the database through that grid.
I found a few old (circa 2008) solutions for creating new records using Copy Paste from Excel. Similarly, is there a way to "update" an existing record in the database by copying a row from Excel and pasting into that "grid"? I have some 60+ and 70+ year olds in the team, and would really like a simple solution that could cater to all ages. Right now, we scroll right and left, furiously, inside the grid trying to ensure that we are updating the correct row of record.
I sincerely appreciate your guidance in this regard.
One way you can do this, though I do not recommend is:
1) Right click the table you want to edit, select edit top 200 rows.
2) Right click the screen that pops up, go to Pane -> SQL
3) Change this to show the records you want to edit and column in the order you want and it should work.
Big problem here and why I wouldn't suggest this, is if anything is wrong you could really mess stuff up, also it will lock the rows you are looking at which could affect other things. A better "work around" would be to create an excel function and use a template. Example : ="Update "&B1&" Set "&C1&" = '"&D1&"' where ID = "&A1 ... Essecially letting Excel write the dynamic sql. In this case B1 would be the table to update, Cell C1 would be the column to update, D1 would be the new value and A1 would be the unique identifier. I do this often when someone sends me a list of 1000 items and I need to put them in a temp table or something.

Running Database in Excel

Is there a way to create a running database in excel (and only in excel, without using third party programs) so for example:
-One worksheet has today's data for each person
-The additional worksheets (one per each person on the first worksheet) keeps a list of each of the past columns
-Each of the worksheets, except for the current worksheet, charts each new row of data added daily.
Here is a picture in case it helps:
This can be done in Excel, but you need to get the data architecture right.
Use ONE sheet for all raw data. Columns are Date, member, score, number of pages, number of files, notes. New data goes at the bottom of the list. You can use VBA to create a data entry form if you don't want to enter data straight into the sheet. The sheet can be hidden, if needed.
Then use ONE other sheet to create a dynamic report where you can select the time frame and the member to report on. Data is pulled from the raw data sheet and aggregated as required. Pivot tables are immensely powerful.
Using a sheet for each member would be duplication of functionality and bad data design.
Edit: a few conceptual screenshots
The raw data table. New data is added at the bottom of the table. A VBA form can ensure a pleasant user interface, so that the user never sees this table.
The report could be a pivot table grouped by date. Slicers allow the selection of specific time frames, for example a month. Another slicer allows filtering by a specific member.
It took me roughly 5 minutes to create the scenario, including making up the dummy data. With a few hours to spend, this could be made really shiny.

Create Graphs automatically out of the excel generated via SSIS?

I have the following requirement,
A SQL Server 2008 scheduled job that runs at 9 am in the morning. This job should send a spreadsheet with data in a workbook(workbook1) and the chart attached in the next workbook(workbook2). The data must have the values from a SQL table. The chart must reflect the values present in the workbook1. This sheet should be mailed across to n number of users. The n number of users are not even aware of the sql server and dont know anything about the username and password of the server. They must just have the spreadsheet with the two workbooks.
I have decided to do the below
1) Create a stored procedure that formats the data into a table 2) Invoke a SSIS , to copy the data into the workbook1 of excel 3) Create the Graph in the workbook2 of the same excel
The point 1 and 2, I have completed already.
After activity 1 and 2, I will have something like below in the excel
Workbook1:
Date | Column A | Column B | Column C |
10-7-14 | 0983883 | 09433344 | 4443333 |
11-7-14 | 0986444 | 06875544 | 4689073 |
I am not really able to do the activity 3. Activity 3 must have take in the values from the above table and create graphs in workbook2
I know it can be done with SSRS, but I would like to know other ways as we have only SSIS with us and SSRS is totally out of scope. For some reasons SSRS is restricted to use in our systems.
I have tried various ways to do this. (created a dynamic graph in workbook2 of the excel template for SSIS and let the values transferred to workbook1 renders the graph but it does not work sadly.). I am not able to create dynamic graphs with the empty excel templates that I feed to SSIS.
Excel is the problem here, it does not allows any pre-defined graphs in it. It always expects a value to create a graphs.
I can also go for a VBA macro option,(like creating a button and let the user click the button to generate graphs) but I am not really sure if it is a feasible one?
Excel experts please help !
I might like sound like an amateur but please pardon me as I am new to SSIS and none of my colleagues have an idea on how to do it and I could not get anything with the research I have done, which is a bit frustrating though.
As I don't know the specifics of your workbook structure you might need to adapt the following vba code (as the sub name suggests this should be placed in the Open event of the workbook):
Private Sub Workbook_Open()
Dim wb As Workbook
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim LastColumnLetter As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1")
Set ws2 = wb.Worksheets("Sheet2")
Application.ScreenUpdating = False
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
LastColumn = ws.Cells(2, Columns.Count).End(xlToLeft).Column
LastColumnLetter = Chr(LastColumn + 64)
ws2.Activate
ws2.ChartObjects("Chart 1").Activate
ActiveChart.SetSourceData Source:=ws.Range("A1:" & LastColumnLetter & LastRow)
ws2.Range("A1").Select
Application.ScreenUpdating = True
End Sub
This code executes when the workbook is opened and first tries to find the range your data table is occupying and then updates the Data Source for the Chart. I have assumed that your data are in Sheet1 and start at cell A1 while your chart (Chart 1) is in Sheet2.
I do something similar for work but am using excel as a front end to SSAS but the concept is similar for sql server.
It sounds like you would find a pivot chart in excel useful. This is due to the fact that excels dynamically renders the chart based on the results of the pivot table.
Note that the pivot table allows for filtering so this means that the user can filter out parts of the data they do not need. Or if the user wants to alter how the chart looks, e.g. sales by month instead of sales by quarter it is extremely easy for them to do. So basically the presentaton of the results are being done dynamically in excel.
To create one based off external data you do the following:
Data --> from other sources
It is possible for excel to query sql server, though you probably want to limit the result set to a small read-only table for reporting.
Note that the data source information is saved into the file, with excel being able to use both user name and password hard coded in or the window's domain logins. Ideally you want to use the domain login over a general username and password
So the solution becomes more like the following:
SP or SSIS to populate a table for excel to query. This means excel is just writing simple selects and group bys
Using Data --> from other sources --> from SQL server
Create the stock pivot table, which will handle the presentation of the data
Give file to users. The file would have the defined datasource in it
They then just hit refresh which will requery the server for the results.
User is able to drag and drop fields, which updates the pivot table and redraws the excel chart
The only downside being that the user can only see a copy of the current dataset.

excel to access records with macro

not sure even where to start on this. i have an excel workbook with tabs for different tracking sheets. some for maintenance tracking and some for personnel work hours for different jobs. it is very time consuming to pull, copy and paste the results i need and then compare them. i already know that an access database would be a better product to use for tracking and pulling results together, however my boss always favors excel and does not want to get rid of the current products used by myself, the boss and a hand full of others in the office. so i already know what needs to be converted to a database but have my hands tied for the time being.
so here is what i am trying to accomplish. my boss has set up macros for several of the excel sheets to archive the days worth of results in maintenance and workers hours spent doing jobs. what it currently does is, makes a copy of the sheet and saves that sheet to a network folder for us to look at if we have a problem and need to check results. i would like to recode the macro to instead save those results to records in an access table. some of the info is missing and would need to be created on the fly as the record is created. because the sheet tracks only results for the day, there is no column in the excel sheet for the date. so the date will have to be added to the record as it is created, which is usually yesterdays date. results get fed into the excel sheet and stay until the next morning when we hit the archive macro button to save yesterdays results to an excel.xls file.
here is a screen shot of the sheet.
dispatch log
so when i try to bring all the days together i have to copy and paste from multiple xls files to one just to get the stats i need. i know my way around access better then i do excel so this would be a great time saver for me. if i could change the archive code to populate an access table would be great help. anybody got any ideas? thanks in advance for helping me.
code used to archive the excel sheet.
Sheets("DISPATCH LOG").Select
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = Format(Now(), "yyyymmdd")
On Error Resume Next
Kill "Y:\Dispatch_Archive" & FileName
On Error GoTo 0
WB.SaveAs FileName:="Y:\Dispatch_Archive\" & FileName
'Delete the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
WB.Close SaveChanges:=True
Maybe you could link access to the workbooks as mentioned here
http://office.microsoft.com/en-gb/access-help/import-or-link-to-data-in-an-excel-workbook-HA001219419.aspx
Kind of using the spreadsheets as four backend databases and then query and update them using the access front end

Resources