SSRS: Repeat Down Total from Matrix in all rows - sql

Need some help in SSRS,
New to this so apologies ahead if not entirely up to scratch with answers.
I am trying to get the Total of a column and repeat the value of that total (Total Checks - see image) across all the rows.
Below is image:
I have tried multiple different ways, each time with failure.
Any help would be much appreciated.
Thanks,

Depending on where you are getting your data from, you have different options. For example, within SQL you could use windowed functions:
select Date
,Checker
,sum(Checker) over () as TotalChecks
,sum(Checker) over (partition by Date) as TotalChecksByDate
from table
or within SSRS expressions by explicitly stating your scope, either for the dataset as a whole:
=sum(Fields!Checker.Value, "YourDataset")
or just for the grouping within your table:
=sum(Fields!Checker.Value, "YourTableGroupName")

Related

SQL Method for Cascading Workload Based on Rank and Available Hours

Recently I created an automated production scheduling tool through Excel that assigns a rank to items being produced in the same process, and then uses that rank in combination with the workload to create a schedule.
It functions exactly the way it is intended to, but due to the large amount of data and it being excel it has very slow performance, which is why I am looking to move the calculations over to SQL.
The general logic is like this:
-Always produce everything from the first day before the second day
-Always produce items from an earlier rank before items from a later rank
You can see how this plays out in the image below, where the line has 21.5 hours today, so items will be produced on day 1 until it equals 21.5, where the remainder is then carried over to day 2 and so on.
I was able to do this in excel using lengthy positional based formulas, but I am trying to think of a way to get the same result in SQL without having to rely on looking at the row above.
I am not sure how to convey something like 'Subtract from the available time production time of higher priority items produced on the same day'.
I apologize if the question is unclear, but any advice would be appreciated.
Image of Production Hours Cascading by Priority and Day
Example of Position-Based Fomula
Thanks to shawnt00, that put me in the right direction. Ultimately I had to modify the case statements a bit to go off of the cumulative total instead, but I was able to get the desired results using a sum() Over (partition by order by ) statement.

Need to Display records Group By in SSRS

In SSRS 2008, I am developing the report that should display the records based on condition: It should give me the amt_total based on gift_type (Here, amt_total and gift_type are columns of the table).
This is the query I am using.
SELECT o110113.gift_batch_no,
o110113.gift_type,
(o110113.gift_date),
o110113.feed_doc_code,
SUM (o110113.amt_total)
FROM GIFT_CARD o110113
WHERE (o110113.gift_type IN
('RR', 'RB', 'CR', 'RM', 'RW', 'CW', 'RJ', 'RO', 'RK', 'CI')
)
GROUP BY o110113.gift_batch_no,
o110113.gift_type,
(o110113.gift_date),
o110113.feed_doc_code
ORDER BY o110113.gift_batch_no ASC, o110113.gift_type ASC
And the report I am trying to generate in SSRS 2008 should look like this.
Clikck this to see the Image of the Report that I am trying to develop
I am trying to use the SSRS expression
=Sum(Fields!SUM_O110113_AMT_TOTAL_.Value,"GIFT_TYPE")
It is throwing me the error saying:
Please click this to see an Error I am getting in SSRS
Kindly provide the Solution
This the report design I have developed
[click to see the Image of report]
Thanks
Arun
Here you need to do group by of your Tablix.
First you need to add Row group on gift_batch_no so that will dispaly based on gift batches.
Another row group your have to create on Gift type and in that second group type you need to set SUM of total amount it will work.
Let me know if you have any other query
That error has to do with the scope of your sum. without seeing the data sets and assuming it is not a nested aggregate operation based on the image. you are trying to reference the column name "GIFT_TYPE" when it should actually be the name of the record set, or the appropriate scope(data region/group).
here is how scope works from the provided link below
The value of scope must be a string constant andcannot be an
expression. For outer aggregates or aggregates that do not specify
other aggregates, scope must refer to the current scope or a
containing scope. For aggregates of aggregates, nested aggregates can
specify a child scope.
you will want to see this link for more information

What is difference between Pentaho DI "variables" and "fields"?

Could not find much information about this. I can see that fields can have multiple copies per row in a transformation. But what are variables? Are they unique across all rows a transformation produces? But, by the name, variables are meant to vary.
What is difference between fields and variables exactly?
Can someone enlighten me please
Thank you
PDI transformations work with a stream of rows that pass through all the steps. The rows consist of a number of fields that the steps can act on, converting them, filtering them, sorting, etc.
Variables are more like a configuration help and have a single value in the transformation. It's very important to remember that they can NOT be set/changed and used within the same transformation, because all the steps execute in parallel!
Example
In your transformation you have a variable called "last_staging_run" and its value is "2017/01/19 05:00:00". This one has been passed to the transformation from the parent job.
You then use it in a Table Input:
SELECT id, product_id, price, number
FROM sales
WHERE purchase_date > ${last_staging_run}
This will give you the new rows since the last staging run with the fields id, product_id, price and number. You might then lookup the product names or filter products with a zero price with other steps, then store it in a table again.

How to get a count of Distinct Dimension values in an SSAS MDX Query

I am trying to write an MDX query to return some information about survey questions. I want Average response and total responses in my results. I have two types of questions. One type of question has a single response. Another type of question can have multiple responses (Pick all that apply). Each question is tied to a question ID and a respondent ID. The following query works (somewhat)
Select NON EMPTY
{
[Measures].[Average Response], [Measures].[Total Count]
} ON 0
, NON EMPTY
{
([Question].[Question ID].[Question ID].ALLMEMBERS)
} ON 1
From [Cube]
Average Response is a combination from both single responses and multiple responses (two different fact tables). The total count is also a combination of the two tables. The problem is that for single response questions, I can just count the number of respondents. For multi response questions that falls down as I can have way more responses than I do people taking the survey. I really want to know how many people provided an answer. To do this, I think I need the distinct count of respondent IDs. So I tried changing my first axis to this.
[Measures].[Average Response], [Measures].[Total Count], DISTINCTCOUNT([Respondent].[Respondent ID])
Well, that doesn't work and I really didn't expect it to. I got "The function expects a tuple set expression for the 3 argument. A string or numeric expression was used." which is rapidly becoming my favorite SSAS error message. I am still green at this and I guess I am still thinking SQL. How can I get an average of the responses and a count of the distinct Dimension values in the same query. BTW, my query does have a slicer and I could provide that if needed but I don't think it relevant as I get the same problems with or without the slicer.
When working with the MDX DistinctCount function, it returns the count of distinct, non-empty tuples of a given set of data. Perhaps try doing something like
DistinctCount({[Respondent].[Respondent ID].members * [Measures].[Total Count]})
so that way you are working with a set (e.g. {...}) of data.
If you're working with a larger set of data, you may want to consider creating a Distinct Count measure. The DistinctCount function itself is a SSAS Formula Engine query while using the Distinct Count measure would allow Analysis Services to use both the Storage Engine and Formula Engine. For more information, please refer to Analysis Services Distinct Count Optimization.

Aggregation of an MDX calculated measure when multiple time periods are selected

In my SSAS cube, I've several measures defined in MDX which work fine except in one type of aggregation across time periods. Some don't aggregate (and aren't meant to) but one does aggregate but gives the wrong answers. I can see why, but not what to do to prevent it.
The total highlighted in the Excel screenshot below (damn, not allowed to include an image, reverting to old-fashion table) is the simplest case of what goes wrong. In that example, 23,621 is not the grand total of 5,713 and 6,837.
Active Commitments Acquisitions Net Lost Commitments Growth in Commitments
2009 88,526 13,185 5,713 7,472
2010 92,125 10,436 6,837 3,599
Total 23,621 23,621
Active Commitments works fine. It is calculated for a point in time and should not be aggregated across time periods.
Acquisitions works fine.
[Measures].[Growth in Commitments] = ([Measures].[Active Commitments],[Date Dimension].[Fiscal Year Hierarchy].currentMember) - ([Measures].[Active Commitments],[Date Dimension].[Fiscal Year Hierarchy].prevMember)
[Measures].[Net Lost Commitments] = ([Measures].[Acquisitions] - [Measures].[Growth in Commitments])
What's happening in the screenshot is that the total of Net Lost Commitments is calculated from the total of Acquisitions (23,621) minus the total of Growth in Commitments (which is null).
Aggregation of Net Lost Commitments makes sense and works for non-time dimensions. But I want it to show null when multiple time periods are selected rather than an erroneous value. Note that this is not the same as simply disabling all aggregation on the time dimension. The aggregation of Net Lost Commitment works fine up the time hierarchy -- the screenshot shows correct values for 2009 and 2010, and if you expand to quarters or months you still get correct values. It is only when multiple time periods are selected that the aggregation fails.
So my question is how to change the definition of Net Lost Commitments so that it does not aggregate when multiple time periods are selected, but continues to aggregate across all other dimensions? For instance, is there a way of writing in MDX:
CREATE MEMBER CURRENTCUBE.[Measures].[Net Lost Commitments]
AS (iif([Date Dimension].[Fiscal Year Hierarchy].**MultipleMembersSelected**
, null
, [Measures].[Acquisitions] - [Measures].[Growth in Commitments]))
ADVthanksANCE,
Matt.
A suggestion from another source has solved this for me. I can use --
iif(iserror([Date Dimension].[Fiscal Year Hierarchy].CurrentMember),
, null
, [Measures].[Acquisitions] - [Measures].[Growth in Commitments]))
CurrentMember will return an error when multiple members have been selected.
I didn't understand much of the first part of the question, sorry...but at the end I think you ask how to detect if multiple members from a particular dimension are in use in the MDX.
You can examine either of the two axes as a string, and use that to form a true/false test. Remember you can use VBA functions in Microsoft implementations of MDX.
I suggest InStr(1, SetToStr(StrToSet("Axis(1)")), "whatever") = 0 as a way to craft the first argument of your IIF.
This gets the set of members on axis number one, converts it to a string, and looks to see if a certain string is present (it returns the position of that string within the other). Zero means not found (so it returns true). You may need to use axis zero instead, or maybe check both.
To see if multiple members from the same dimension were used, the test string above would have to be more complicated. You want to know if whatever occurs once or twice. You could test if the first occurance of the string was at the same position as the last occurance (by searching backwards); though that could also mean the string wasn't found at all:
IIF(
InStr(1, bigstring, littlestring) = InStrRev(bigstring, littlestring),
'used once',
'used twice or not at all'
)
I came across this post while researching a solution for my own issue with grand totals of calculated measures over time when filters are involved. I think you could have fixed the calculations instead of suppressing them by using dynamic sets. This worked for me.