I have a Mondrian/MDX query where I grab data within a date range, but I'd like to return time as the value of its property in the result. My current query is like:
With
set [*TIME_RANGE] as '{[Time].[2011].[3].[9].[1].[1].Lag(30):[Time].[2011].[3].[9].[1].[1]}'
set [*PXMD] as '[meta_pixel_id1.Pixel].[label].Members'
set [*BASE_MEMBERS] as 'NonEmptyCrossJoin([*TIME_RANGE],[*PXMD])'
Select
{[Measures].[total_users],[Measures].[total_action_pixels]} on columns,
[*BASE_MEMBERS] on rows
From [ActionPixels]
Where [Pixel ID].[500]
Which returns a result like:
Axis #0:
{[Pixel ID].[500]}
Axis #1:
{[Measures].[total_users]}
{[Measures].[total_action_pixels]}
Axis #2:
{[Time].[2011].[3].[8].[4].[24], [meta_pixel_id1.Pixel].[500].[Action].[Type].[Handraiser]}
{[Time].[2011].[3].[8].[4].[24], [meta_pixel_id1.Pixel].[500].[Action].[Type].[Lead]}
{[Time].[2011].[3].[8].[4].[24], [meta_pixel_id1.Pixel].[500].[Action].[Type].[Shopper]}
Row #0: 3
Row #0: 3
Row #1: 4
Row #1: 4
Row #2: 2
Row #2: 2
Which is what I expect. Problem is, I'm writing this query for use in a Pentaho xaction, so I have some Javascript code afterwards that converts this into a JSON format and when I got to extract the value of the [Time] column, I get back only the day number (in this case, 24). What I want to display instead is the property of the [Time].[Day] dimension we call Date String that contains the date formatted as year-month-day. But none of the examples I can find of how to do this will work with my selection on [Time] by range.
The most immediate solution seems to be to display the Date String property, but I'd be willing to entertain other ideas that will let me get both the data I want and filter on the time range I want.
I was able to solve the problem based on the code found online. I had tried something like that before, but it wasn't working because of what was ultimately a problem with the property in the cube that caused it to always return null rather than the value in the table the time dimension was created from.
Related
enter image description hereI am trying to design a report in ssrs that returns the last opening stock for each product in the dataset. To achieve this I used
=Last(Fields!CustProdAdj_new_openingstockValue.Value).
This works fine. But where I encountered a problem is in getting the sum of all the opening stock for each product. I tried using
=sum(Last(Fields!CustProdAdj_new_openingstockValue.Value))
but I got the error message
[Error on Preview]
Please is there another way to go about this
I have tried using aggregate(), runningValue(), to no avail
This is the dataset
This is the report layout
On previewing having used max()
This is probably easier to do directly in the dataset query but assuming you cannot change that, then this should work...
This assumes your data is ordered by the CustProdAdj_createdon column and that this is a date, datetime or some other ordered value, change this bit if required.
=SUM(
IIF(Fields!CustProdAdj_createdon.Value = Max(Fields!CustProdAdj_createdon.Value, "MyRowGroupNameHere"),
CustProdAdj_new_openingstockValue,
0)
)
Change the MyRowGroupNameHere to be the name of the rowgroup spelled exactly as it is in the rowgroup panel below the main design panel. Case sensitive and include quotes.
What this does is, for each row within the rowgroup "MyRowGroupNameHere", compare the CustProdAdj_createdon date to the max CustProdAdj_createdon across the rowgroup. . If it is the same then return the CustProdAdj_new_openingstockValue else return 0.
This will return the value required on only 1 record within the group.
For example, if you had 1 row per day then only on the last day of the month would a value be returned other than 0 because only the date of the last record would match the maximum date within the group.
Then it simply sums the results of this up.
The logic which we are trying to achieve in single query is as follows.
We need to loop based on row number column. So, on each loop we need to sum-up remaining value and new value.. resultant value to be updated in "by summing up column". and the decimal part to be updated in decimal value column.
in next step, need to sum-up the decimal value column by grouping on row number. and the resultant to be updated in remaining value column of next row number
the above step 1-2 to be continued till we reach last record.
We achieved this through while loop.. But trying to achieve this without while loop.
Can someone please give idea to achieve this
Please refer the attached image for understanding table
enter image description here
Please look at the image below, my dataset has two processes, 'logs processed' and 'stacked at kilns'.
I need to take the total 'stacked at kilns' and divide it by the total 'logs processed' for each length.
so for example for field name 5.4 (dataset field length), I would like to divide 2784/2283 to return a percentage of the recovery.
my expressions currently is
=Sum(IIf(
(Fields!process.Value = "Logs Processed") AND (Fields!Length.Value=Fields!Length.Value)
, Fields!cubes.Value
, Nothing)
, "Wetmill_to_Kiln")
But this returns the value of all lengths where process is 'Logs Processed' not for just length 5.4 as per example.
So each length field is dynamically created (3.3,3.6,3.9 .... 6,6.3,6.6)
I would like to get the total for 'stacked at kiln'/'logs processed' for each length field.
any help appreciated as always
example of my desired output in bottom image.
current output:
Desired output:
*****UPDATE AS PER TPHE*********
I have created a text box inside the column group. this returns the value for that group but how can I reference the value of that text box.
if I use something like ReportItems!tbxSource.Value how can I reference the value of the textbox when the it is dynamically created across the column group? there are then mulitple instances of that textbox name?
with reference to the picture how do get the value of the white <> from the textbox with green <>
Thanks,
Since you are using a column group, you can put your expression into a text box within the group and it will execute on only the data that is captured within each column. So if your code for the Logs processed row is something like Sum(Logs) and your code for the Stacked at Kiln row is something like Sum(Stacked), your expression code for the recovery row would be Sum(Stacked)/Sum(Logs). The key is to make sure that it is within the column group.
So what I got to work was to create two variables on the column group. one called kilntotal and one called logtotal. the variables value was equal to the result of this expression:
=sum(iif(Fields!process.Value="logs",cdbl(Fields!cubes.Value),cdbl(`0)))`
and
=sum(iif(Fields!process.Value="kiln",cdbl(Fields!cubes.Value),cdbl(0)))
I then use these variable in my logic in my recovery % row:
=Variables!kilntotal.Value/Variables!logtotal.Value
Thanks for the input and your time.
When connecting from powerpivot to SSAS, I got the following problem - if for some reason no rows are returned by mdx query, no column names are returned either and powerpivot gives an error. When executing such a query in SSMS I got 0 rows if mdx returns nothing and 2 rows if mdx returns 1 row (column names and the row itself). So - can I somehow force SSAS to return column names?
Query currently looks a bit like this:
SELECT NON EMPTY {[Measures].[Measure1]} ON COLUMNS,
NON EMPTY {Filter([DimLocalDate].[Date].&[20110101]:[DimLocalDate].[Date].&[20120101],
[JobStatus].[JobStatus].&[1] } ON ROWS
FROM [TheCube]
In my app customer can specify dates and status value. If no results are found I would expect an empty result set, but instead I got an error.
Thanks.
re SSIS error: [MEMBER_CAPTION] cannot be found at the datasource.
Thanks your solution helped me.
I had the same issue using SSIS, SSAS to output a flat file report
i'll post an extended example to help others define the dummy set.
Please note that the date is inserted into MDX script dynamically.
SSIS throws an exception when no data exists for the date, and therefore no results are returned.
This messes up the column order
--create a blank set so that data is still returned when there are no results for that date
set [BlankRowSet] as
([Activity Period].[Days].[Day].&[2014-02-02T00:00:00], [Well].[Location].[Location].&[])
--create the active set as the crossjoin between Days, Wells
set [ActiveSet] as
nonempty([Activity Period].[Days].[Day].members * [Well].[Location].[Location].members )
SET [RealSet] as IIF(COUNT([ActiveSet]) > 0, [ActiveSet], {[BlankRowSet]})
select {[Measures].[Total boe]} ON COLUMNS
,[RealSet] ON ROWS
FROM
(select {[Activity Period].[Days].[Day].&[2014-02-02T00:00:00]:[Activity Period].[Days].[Day].& [2014-02-02T00:00:00]} on 0 from [Volumes] )
where
[Scenario].[All Scenarios].[Category].&[PVR Sales Estimates]
I will check before the select if your NonEmpty clause will return a void set, and in that case put on row a dummy set that will be return to powerpivot at least 1 row.
Something like:
WITH
SET [mySet] as NON EMPTY ({Filter([DimLocalDate].[Date].&[20110101]:[DimLocalDate].[Date].&[20120101], [JobStatus].[JobStatus].&[1] })
SET [myRealSet] as IIF(COUNT([mySet]) > 0, [mySet], {[DummySet]})
SELECT NON EMPTY {[Measures].[Measure1]} ON COLUMNS,
[myRealSet] ON ROWS
FROM [TheCube]
would help?
I am trying to use Set Analysis in the table below for the column labelled test. I am trying to get sum([Best Dollar]) for the date range specified by the Start and End columns.
This expression returns results, but it's naturally static for each row of the table:
=sum({$<AsAtDate={">=40959 and <=40960"}>} [Best Dollar])/1000
This is what I want to have but it returns 0:
=Sum({$<AsAtDate={">=(num(floor(BroadcastWeekStart2))) and <=(num(floor(BroadcastWeekStart2)))+6"}>} [Best Dollar])/1000
To obtain unique start date serial numbers for each line for the start column (BroadcastWeekStart2) I use the following expression:
=(num(floor(BroadcastWeekStart2)))
How can I specify that the values or calculations used for the start and end columns are used in Set Analysis for the field above?
There is at least one information missing in your question.
Do you want to select on fixed values or should the sum depend on the current time?
For the static version something like
=sum( {$<BroadcastWeekStart2={"40959"}, BroadcastWeekStart2={"<=40960"}>} [Best Dollar])/1000
should work. (Assuming that BroadcastWeekStart2 contains these kind of values.)
Let me show you an example how I calculate values for the current week:
='Count: ' & count({$<start_week={"$(=WeekStart(Today()))"}>} Games)
where the start_week is set in the load script by:
WeekStart(date#(#4, 'YYYYMMDD')) as start_week,