basic mdx question using Ms Excel OLAP tools - mdx-query

I will make this question and scenario as basic as possible since I have no background on programming. How do I make a script where all red will be multiplied by 5, yellow by 6 and blue by 7? The new measure will aggregate in grand total. I don't know what expressions to use. Just use [Product] for the colors and [Measure] for qty.
enter image description here
I dont understand yet the use of MEMBERS and other expressions as this is my first time to be on it. I tried
([Measure].[Quantity],[Product].&[Yellow])*6
but it will just multiply everything with 6. Maybe FILTERS? IIF? I just don't know how. The script will go a long way when I will apply it in our database. thanks!

I know you asked about doing this with excel, but if you were writing an MDX query you could do create a new measure and run the query like this:
WITH
member measures.[ColorQuantity] AS CASE WHEN [Product].[Product].currentmember.member_key = "Yellow" THEN measures.[Quantity] * 6
WHEN [Product].[Product].currentmember.member_key = "Blue" THEN measures.[Quantity] * 5
WHEN [Product].[Product].currentmember.member_key = "Red" THEN measures.[Quantity] * 2
ELSE measures.[Quantity] END
SELECT {
measures.[Quantity], measures.[ColorQuantity]
} ON 0,
Non EMPTY
{
[Product].[Product].[All].Children /// I dont know the FULL dimension AND hierarchy path you want TO use
} ON 1
FROM YourCubeName
This might help you get started.

Related

Report builder (SSRS) SWITCH statement blank values

For a report I'm building, there are fields that are dependent on a user selecting to add additional people to their policy (named in the dataset as dependent1, dependent2, etc).
We need to determine whether these dependants are adults or children for reporting. This will be done via DOB and a DateDiff which I understand
Currently, I can get the report to show ADULT or CHILD if data is present, however if there isn't any data I can't return a "" value, it just defaults to ADULT.
I'm using:
=Switch(DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) < 18, "CHILD",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) >= 18, "ADULT",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value), "")
I also created another column which uses the DateDiff between Fields!Dependant1DoB.Value & Fields!Policy_Start_Date.Value to show the number of years. This works and returns a number. however for some unknown reason where there's no data it still returns "2019" which may be effecting it? I've tried including this in the Switch statement (DateDiff("yyyy",Fields!Dependant1DoB.Value,Fields!Policy_Start_Date.Value)=2019, "")) but this still doesn't work.
Someone please help as this is driving me loopy!
You need to first check for nothing and then apply the switch function, example below:
=IIF(IsNothing(Fields!Dependent1DoB.Value),"",
Switch(
DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)<18, "CHILD",
DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)>=18, "ADULT"
)
)

Is it possible to add multiple SetExpressions within an IF statement?

I am having troubles trying to make a graph work. I am not entirely sure if this is possible, thus me asking here. I have below graph, which has the expression:
=Count{<Year='2014','2015','2016'},Month='Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT sicknumber)
So it doesnt change with whatever selection has been made in the filters. it always shows 2014, 2015, 2016
I want to be able to make the graph non static based on the filter that is given. If I select year 2015 I want to show the previous year and the year after. so when selecting 2013 I want to see 2012, 2013 and 2014. I have made the following expression:
=
if(Jaar = '2016',(Count({<Jaar={'2015','2016'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2015',(Count({<Jaar={'2014','2015','2016'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2014',(Count({<Jaar={'2013','2014','2015'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2013',(Count({<Jaar={'2012','2013','2014'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2012',(Count({<Jaar={'2011','2012','2013'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)))))))
it seems however that it ignores the set expression and just show the year given in the filter. How would I go around this.
When using the same statement to just calculate to total unique values in a text object, it does seem to be able to calculate the correct value there.
how would I go around this, of is it even possible?
thanks in advance
=Count({<Jaar={$(=Max(Jaar) - 1), $(=Max(Jaar)), $(=Max(Jaar) + 1)}, Maand>} DISTINCT Ziekte_Volgnummer)
Seems to be the right answer.

Grouping Elements on Conditions in Penthao Report Designer

I want to make a Report in Penthao Report Designer
My SQL query tells me the SUM of some variables and another variable is already the same SUM.
So for Example
DATE Name Expected SUM
Today A 20 20
Today B 10 5
Inside the Report Designer i select a Text field which is OK if Expected-SUM=0 else Error.
Inside my Report i know want to display if for "Today" all those Textfields are OK (than one row should display OK) or if at least one of them is Error than only Display one Row with Error for a given Date
I'm thankfull for every suggestion.
As here are no suggestions so far, maybe this is one solution: I would do this with an JavaScript-Step, but as a tranformation with a field and a filter-step:
Javascript:
var testing = "";
if(expected - sum == 0){
testing = "ok";
}
else {
testing = date;
}
And after that a filter-step, which sends rows to an "error"-output-report (with given date): filter is "testing NOT ok".
Sorry if thats not the solution for your problem, I have no experiences with Reports ... But maybe it's a hint and you asked for "every suggestion" :)
Hope it works!

How to change values in facet to same in Google Refine?

I'm trying to clean this data: https://dl.dropbox.com/u/820037/local_council_election_data_w_occupation.gz
It's all the candidates for a local councils' election in Finland. In the column "Ammatti" there is the occupation of a candidate as reported by him/her.
I want to find all the students, but the problem is, that they can be "opiskelija" (student) or "yliopisto-opiskelija" (university student) and things like that.
I clicked the column title "Ammatti" and Filtered it with "opiskelija", then I created a "text facet" from the menu in column title.
That gives me the following facet:
agrol. opiskelija AMK 1
agrologiopiskelija 9
agronomiopiskelija 1
...and so on.
I'd want to change the value of "Ammatti" (occupation) to "opiskelija" (student) in everyone of these occasions.
To make thngs a bit more complicated the facet has also some occupations (mature students and administrative staff) I don't want to change to "opiskelija":
aikuisopiskelija 10
opiskelijakunnan hallituksen varapuheenjohtaja 1
opiskelijapalvelun päällikkö 1
opiskelijapalvelupäällikkö 1
I did this by hand clicking through the whole list in the facet and changing the occupations one by one.
I suppose there is a better way to do this, but could someone please tell me how I should've done it?
Using the 'include' option in the facet, select all the rows that you want to transform from the column "Ammatti". Then in for this column invoke the Transform function and replace "value" by "opiskelija"
This will replace all the value you have selected by "opiskelija".
Hope this help (and it doesn't come too late).

MOSS 2007: What is the source of "Directories"?

I'm trying to generate a new SharePoint list item directly using SQL server. What's stopping me is damn tp_DirName column. I have no ideas how to create this value.
Just for instance, I have selected all tasks from AllUserData, and there are possible values for the column: 'MySite/Lists/Task', 'Lists/Task' and even 'MySite/Lists/List2'.
MySite is the FullUrl value from Webs table. I can obtain it. But what about 'Lists/Task' and '/Lists/List2'? Where they are stored?
If try to avoid SQL context, I can formulate it the following way: what is the object, that has such attribute as '/Lists/List2'? Where can I set it up in GUI?
Just a FYI. It is VERY not supported to try and write directly to SharePoint's SQL Tables. You should really try and write something that utilizes the SharePoint Object Model. Writing to the SharePoint database directly mean Microsoft will not support the environment.
I've discovered, that [AllDocs] table, in contrast to its title, contains information about "directories", that can be used to generate tp_DirName. At least, I've found "List2" and "Task" entries in [AllDocs].[tp_Leaf] column.
So the solution looks like this -- concatenate the following 2 components to get tp_DirName:
[Webs].[FullUrl] for the web, containing list, containing item.
[AllDocs].[tp_Leaf] for the list, containing item.
Concatenate the following 2 components to get tp_Leaf for an item:
(Item count in the list) + 1
'_.000'
Regards,
Well, my previous answer was not very useful, though it had a key to the magic. Now I have a really useful one.
Whatever they said, M$ is very liberal to the MOSS DB hackers. At least they provide the following documents:
http://msdn.microsoft.com/en-us/library/dd304112(PROT.13).aspx
http://msdn.microsoft.com/en-us/library/dd358577(v=PROT.13).aspx
Read? Then, you know that all folders are listed in the [AllDocs] table with '1' in the 'Type' column.
Now, let's look at 'tp_RootFolder' column in AllLists. It looks like a folder id, doesn't it? So, just SELECT the single row from the [AllDocs], where Id = tp_RootFolder and Type = 1. Then, concatenate DirName + LeafName, and you will know, what the 'tp_DirName' value for a newly generated item in the list should be. That looks like a solid rock solution.
Now about tp_LeafName for the new items. Before, I wrote that the answer is (Item count in the list) + 1 + '_.000', that corresponds to the following query:
DECLARE #itemscount int;
SELECT #itemscount = COUNT(*) FROM [dbo].[AllUserData] WHERE [tp_ListId] = '...my list id...';
INSERT INTO [AllUserData] (tp_LeafName, ...) VALUES(CAST(#itemscount + 1 AS NVARCHAR(255)) + '_.000', ...)
Thus, I have to say I'm not sure that it works always. For items - yes, but for docs... I'll inquire into the question. Leave a comment if you want to read a report.
Hehe, there is a stored procedure named proc_AddListItem. I was almost right. MS people do the same, but instead of (count + 1) they use just... tp_ID :)
Anyway, now I know THE SINGLE RIGHT answer: I have to call proc_AddListItem.
UPDATE: Don't forget to present the data from the [AllUserData] table as a new item in [AllDocs] (just insert id and leafname, see how SP does it itself).