SSAS dates not working in an Excel filter - excel

In my SSAS cube I have a dimension that includes 6 date fields. They are all defined in the same way, with a Key field that is a date type and a Name field that is char(10) in format yyyy-mm-dd.
When I include those fields in an Excel pivot table, they all work fine except one. That one field is displayed correctly, but doesn't behave correctly when filtered. In particular, specifying a between filter always returns zero rows. Same with a greater than filter. Begins with works fine.
Once again, this only happens for one of the six date fields. But all six date fields are configured identically as far as I can tell. What type of mistake could cause this?
EDIT
Using SQLServer Profiler I can see that the MDX generated from Excel are identical for the dates that work and the one that doesn't (except for the field names changing of course). If I restrict the pivot table to a single date and add a between filter then the MDX is:
SELECT NON EMPTY Hierarchize({DrilldownLevel({[Participation Program].[Participation Start Date].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS
FROM (SELECT Filter([Participation Program].[Participation Start Date].[Participation Start Date].AllMembers,
([Participation Program].[Participation Start Date].CurrentMember.member_caption>="1985"
AND [Participation Program].[Participation Start Date].CurrentMember.member_caption<="1990")) ON COLUMNS
FROM [Compass3])
WHERE ([Child].[Child is Handicapped].&[T],[Measures].[Child Count]) CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
That returns correct results for [Participation Start Date], but if I do the same thing with [Participation Stop Date] it returns 0 results. So it is a problem on the SSAS side rather than Excel side. But I still can see no difference in the way the two dates are configured in the cube, and I am 100% certain that there is data that should match the specified date range.

I would change the Key for those attributes to a numeric representation of the date in YYYYMMDD format. I would achieve this via a SQL View where I would use the CONVERT function.
I would not use the date datatype at all in SSAS, as it's internal representation is obscure/uncertain.

I've come across a similar problem using epplus. If you haven't defined the date explicitly, Excel may not realize that the data is a date. This causes problems with sorts and filtering. (Note that the code below is C#, but the idea behind it with respect to the excel formulas/formats should be the same.)
When you generate the excel cell, explicitly define a date formula in the cell:
ws.Cells[rowCount, columnCount].Formula = "=DATE(" + myDate.ToString("yyyy,M,d") + ")";
Then, set the cell formatting to display the date the way you want:
ws.Cells[rowCounter, columnCount].Style.Numberformat.Format = "d-mmm-yyyy";

Related

Excel Power Query truncating text field to 1024 characters

I am accessing a SSAS DMV through Power Query in Excel via:
let
Source = AnalysisServices.Database(TabularServerName, TabularDBName,
[Query="select * from $SYSTEM.TMSCHEMA_EXPRESSIONS"])
in
Source
This works great in Power BI, but in Excel, the Expression column is limited to a max of 1024 characters. How do I get Power Query in Excel to give me the entire value? My largest values are around 15000 characters, so still within the stated limits of Power Query that I can find.
If I set up a table with a connection and query behind it, Excel can pull in the entire Expression column, but the downside is the server and database cannot be parameterized and have to be manually changed in the connection. Also I don't remember how to do this manually, so I always have to access the DMV from DAX Studio and export to Excel to set it up!
Update
I did some heavy transformations of this column. I parsed out a value, I used it to merge the file with itself and add a column that I then did a bunch of transformations on, and then used it to replace text within the original problem column. And something in that pulled in the whole value. I tried just doing small parts of this, like adding a column that referenced the problem column, or doing a replace in the problem column, and none of that worked.
So, no, not easy to duplicate or figure out which step fixed it, but for my purposes, I now have what I need.
I think it is related to the type of the column your are loading in Excel. I had the same issue and read your answer (with Table.ReplaceValue).
Your solution is hiding the initial point : The function used in the expression you shared for Table.ReplaceValue() is Replacer.ReplaceText that as the additional specificity to convert a field of type Any
to type Text.
I tried to juste change the type of my field that was truncated when loaded in Excel, from type Any to type Text. Result : the complete values were then loaded in my worksheet.
I had to change this query today, and after I changed it, the values were truncated again. I added a Replace Value step at the end of the query on the truncated column and that seemed to fix it.
#"Replaced Value" = Table.ReplaceValue(#"Last Step","in ","in ",Replacer.ReplaceText,{"Truncated Column Name"})
in
#"Replaced Value"

Transform data types in parts of a column

I am retrieving data through Power Query from an Oracle DB live to an Excel workbook. In PQ, under the "Transform" tab, there is a function to change the data type of a column, that I use to get all the decimal numbers displayed. In the M-code the function is called TransformColumnTypes. However I have some strings in the data that I cannot change to decimal number and produce an error. Is there a way to exclude these? Because the function takes the whole column at the moment.
Before applying function
Function producing error
Code
I don't think so. If you have multiple types within a column, text is the only one that doesn't produce errors.
But if it is only the first row like in your image, promoting it to header before setting the column type will fix the issue.

SSIS Loading Just The Date From Excel Sheet

I have an Excel file with multiple sheets, but only the first sheet has the date listed on it. What I was trying to do was read the excel file, put it into a variable to be able to be used later on in a data flow task.
Normally it would be your run of the mill read and write data flow task, but since this information lies in the first page of the excel sheet with just mostly information about the report, it makes reading the information a bit more difficult.
Here's what the sheet looks like, and the only information that I was wanting from this whole sheet was on the Data Period line more specifically, Dec 2016
Any direction would be greatly appreciated, thank you.
Excel sheets can be queried like tables. You can use an Execute SQL Task to read a range of cells iterate over the results, or you can read a single cell as if it were a range and store its value in a variable.
The process is described in Read Excel Value in SSIS and contains quite a few gotchas :
Add an Excel conneciton manager that points to your Excel file
Set its result type to Single Row.
Set the query to SELECT * FROM [Sheet1$A6:A6]. That's the first gotcha. You can't specify column names. In a dataflow query you can write SELECT RIGHT(F1,8) FROM
[Sheet1$A6:A6] to extract only the date part. This doesn't work in
the Execute SQL Task.
In the Result Set section, map the 0 result set to a new string variable, eg PeriodCell. The name has to be 0. That's the second gotcha
You can create another variable based on an expression that returns only the 8 rightmost characters of PeriodCell, eg RIGHT( #[User::PeriodCell],8)
You can parse the string directly into a date if your system uses an English locale. In this case, you could create a DateTime variable with an expression (DT_DATE)RIGHT( #[User::PeriodCell],8). For example, (DT_DATE)"Dec 2016" returns 1/1/2016
Unfortunately, this won't work if your locale is not English, even if you change the package's Locale property.
If you have load the content of the cells of the "Data Period" column into a SQL table with SSIS, you can easilty convert them from excel date format to SQL date format usign one of the following:
Date and time
select dateadd(second, (#time_xls - ROUND(#time_xls,0))*86400, dateadd(d, ROUND(#time_xls,0),'1899-12-30'))
For example the value 42853.4673611111 is converted into "2017-04-28 11:13:00.000"
Only date
select dateadd(d,#time_xls,'1899-12-30')
For example the value 36464 is converted into "1999-10-31 00:00:00.000".

Which is the most flexible way for end-user to create a report querying an SSAS Cube?

I know that you can query a cube by connecting from Excel to Analysis database and using formulas like cubevalue() or cubemember().
I also know that after converting the power pivot to formulas, you can access the attribute and the value related only by writing a text.
Example: for Branch Dimension, instead of writing
cubemember("connections";"[DimBranch].[Name].[All].[London])" )
you can write in the cell only "London". However, this won't work if you have a parent-child dimension and want to retrieve the amount for one of the intermediate levels.
Did anyone know about how can you avoid writing these formulas directly by the end-user ?
I´ve done this several times. I can describe the approach I´ve used in the past.
You need to define the input from the user, for example Fiscal Year, Fiscal Period,... and create a tab with a friendly layout for this solely purpose.
After that you create your pivot/pivots against the cube/s you want to query with the data extraction that you need (obiously these pivots will refer to the Fiscal Year and Period). Define the desired layout for these pivots (as you want them you be shown). Once You´ve done this, you need to convert into formulas these pivots, including parameters. You´ll see that values placed in the measure box contain a formula cubevalue which makes reference to the connection itself and several cubemembers. It makes reference to the measure as well.
The trickiest part comes now, when you need to modify your cubemember function to take value from the input, something like cubemember("connections";"[DimBranch].[Name].[All].["+MyReferenceCell+")" ), and you have your dimension picked up from a value entered by a user.
If you have as a matter of fact, serveral pivots referencing common dimensions, you need to make the reference this modified cubemember cell affected by user input, otherwise you have to modify all affected cubemembers in your pivots converted to formulas.
This has a really good advantage: depending on the excel´s version, all pivots are automatically recalulated if you change the value in the user´s input cell without hitting the refresh all button.
On the other hand, the disadvantage comes when your report in excel contains a list of values from a dimension which can grow. After converting pivots into formulas those new values for the dimension are lost. That´s why you can always place a control if you have the total value int he pivots regardless the dimension value.
I hope this helps.
Regards

Error in Calculated Column (using Today) in DataSheet View - Sharepoint 2010

I have calulated column which display's the value based on the difference between today and requested date field.
=Today-[Requested Date]
This is working fine in Sharepoint Standard View. But the same is not working with the datasheet view . The calculated column is showing as below
=#NAME?-[Requested Date].
Due to this i am not able to save the data. Can anyone please let me know how to solve this ?
Which SharePoint version are you using?
I tried the same scenario using SharePoint 2013 and was able to add the values in both standard and datasheet views. I am assuming you might have used the same steps.
Create 2 new columns named RequestedDate(DateTime) and
Today(Single line of text).
Add a new column of type calculated field with formula
=Today-[Requested Date].
Now delete the Today column.
Try entering the data in both the views.
First I have used today() function to calculate difference between 2 days except working days. The list is not automatically updating. If we change the Start_Date, then it calculates and gives the value. Can you suggest me why this happens?
You have mentioned in your post that there is some tricks in using today() function. I have created separate Today_Date column in my list. And Used the same column name in finding difference between 2 days. Here also the same problem exists.
The formula I used is,
=IF(AND((WEEKDAY([Today Date],2))<(WEEKDAY([Release Date],2)),((WEEKDAY([Release Date],2))-(WEEKDAY([Today Date],2)))>1),(((DATEDIF([Release Date],[Today Date],"D")+1))-(FLOOR((DATEDIF([Release Date],[Today Date],"D")+1)/7,1)*2)-2),(((DATEDIF([Release Date],[Today Date],"D")+1))-(FLOOR((DATEDIF([Release Date],[Today Date],"D")+1)/7,1)*2)))
Please tell me how to make the difference between 2 date values update automatically every time I open the list.
Then I tried the trick which you have mentioned above. But it works while I enter the data. When I open the list for the next day or some other day's after the Calculated column is not taking the current day's value, do the data remains same. what should I need to do in case it needs to take current date's value and calculate the formula?

Resources