I need to build a paginated report (matrix) where I only display in the column group the top 12 City Area by Net sales. In order to include the ranking I need to have Addcolumns and Summarize functions (Ranking doesn't work with summarizecolumns).
the report will look like the following pic:
But Summarize function doesn't allow columns from other tables and I need to have the business units in there, I've been trying for days to figure this out :( any help would be very appreciated!
this is my code so far:
Define
VAR _Version="01"
VAR _Country ="United States"
EVALUATE
ADDCOLUMNS(SUMMARIZE(
'Dim - CostCenter'[Country],
'Dim - Period'[Period Date],
'Dim - Flow'[Flow],
'Dim - CostCenter'[Stores],
'Dim - Reporting Unit'[Business Unit],
'Dim - Reporting Unit'[Sort_image],
FILTER(VALUES('Dim - Period'[Version]), ('Dim - Period'[Version] = _Version)),
FILTER(VALUES('Dim - Flow'[Flow Code]), ('Dim - Flow'[Flow Code] = _Flow)),
"Net Sales", [Net Sales]
),
"Ranking", RANKX(ALLSELECTED('Dim - CostCenter'[City Area]), [Net Sales],,0))
)
Summarize function doesn't allow columns from other tables
Try with the newer SUMMARIZECOLUMNS instead. See Introducing SUMMARIZECOLUMNS
Thanks David but Ranking doesn't work inside summarizecolumns but I ended up breaking the code in half, on the first one I do summarizecolumns and on the second one I do addcolumns and I add the ranking. that solved it for me
Related
I am new to SSRS and have a SUM(IIF question.
My data set contains four columns: Date, GroupID, PlanPaid, and NetworkIndicator.
Here is an example of the data set:
I am trying to SUM the [PlanPaid] amount when [NetworkIndicator] = "In Network".
However, I need this amount broken up by the [Date]. I tried accomplishing this by creating the expression:
=Sum(IIf(Fields!NetworkIndicator.Value = "In Network"
, Fields!PlanPaid.Value
, Nothing)
, "Claims_Rolling12")
But this expression returns the same amount (total) across all [Dates]. How do I break it up so that it is grouped by the correct [Date]?
Here is a photo of my Tablix and my current Groups: [Tablix and Groups]
And here is a photo of the output: [Output]
You haven't said where you want this sum to appear, so the answer here might not work. If it doesn't then edit your question to show what you expect the output to look like based on your sample data.
I'm assuming here that you want to add a new column to the report that shows "In Network total" by date.
The easiest way to do this is to add a row group that groups by date, then within this group you can use a simple expression, like the one you tried, but without specifying the scope.
=SUM(IIF(Fields!NetworkIndicator.Value = "In Network", Fields!PaidPlan.Value, Nothing))
This expression will only sum rows that are within the current scope, in this case the scope will be the row group you created to group by dates.
As IO said, if this is not helpful, edit your question and show what you expect your end result to look like, based on the sample data you supplied and then I can look at it again.
My query name:
Total Daily Orders Summary
My Input [2 columns]:
business_date,# Daily Orders
I need these 3 columns as calculated output:
Orders# (7 days) Average, Orders# (30 Days) Average ,Orders# (Acuum Average) [i.e.from day one to date]
I have tried my best to find clear answers for how to do moving/rolling average in Microsoft Access query but unfortunately, I couldn't make it work for me. Therefore, I have decided to put my request here to see if someone will put me in the right direction to start working on my files and tasks.
I have trouble with correlated subqueries myself. here is a VBA/Access solution that I think is easier.
Start by adding a code module to your Database by clicking create on the menu and selecting module -which is all the way to the right.
Then create a public function like:
Public Function AverageOrders(CurrentDate As Date, NumberofPriorDays As Integer) As Integer
AverageOrders = DSum("DailyOrders", "MyTable", "business_date BETWEEN #" & CurrentDate & "# AND #" & DateAdd("d", -NumberofPriorDays, CurrentDate) & "#")
End Function
we create the function this way so access intellisense works. This is a powerful technique which I also use to wrap any calls to access form parameters. To find the function in a query right click on the top of a query column and choose build. In the build wizard under expression elements select functions then your database. Average Orders and any other public functions you make will appear. Or just type it.
then you get:
February has 28 days. We don't use # for DateOrders because In strings # denotes a date. To get the accumulated average just pick an absurdly early date or make another function without [NumberofPriorDays].
My employee's IT department refuses to install R for me (claiming the open source version is a security risk) and I tried to create reports with Microsoft Access 2010.
I got stuck trying to create a query on a simple table of hospital wards (for the purpose of keeping track of a data collection exercise):
I did not manage to allocate each ward a sample size that would be proportional to its bed capacity (third column above) as I was not able to refer to the sum of the elements in the "bedCapacity" column. With Excel, I would try something like this:
Cell D2 in Excel contains =INT(C2/SUM(C$2:C$6)*50)+1 and cells D3 to D6 according formulae.
Is there any way I can refer to the sum in the bedCapacity column in Access 2010? I tried creating a separate query that would sum up the the 'bedCapacity` column, however could not figure out how to refer to the value in that query.
I'm trying to use Access 2010 so I can create standardised reports for the data collectors on their progress (which is not easily possible with Excel 2010, as it requires too much manual manipulation - I tried pivot tables etc.).
Would be grateful for any insights.
Create and save this query to give you the total bed capacity from all wards.
SELECT Sum(bedCapacity) AS TotalBeds
FROM YourTable;
Replace YourTable with the name of your table, of course. For the rest of this answer, I will pretend you saved that query with the name qryGrandTotalBedCapacity.
Then you can use that query in another where you cross join it with your table. The cross join gives you a result set which pairs each row of one data source with every row of the other data source.
However, since qryGrandTotalBedCapacity returns only a single row, this amounts to just making the TotalBeds value available for every row of YourTable. And, from that starting point, it is easy to translate your Excel formula to the Access SQL equivalent.
SELECT
y.ID,
y.ward,
y.bedCapacity,
(INT((y.bedCapacity/q.TotalBeds) * 50) + 1) AS sampleSize
FROM YourTable AS y, qryGrandTotalBedCapacity AS q;
My RoundSum function will do that:
Public Sub ListSampleSizes(ByVal BedCapacity As Variant, ByVal SampleSum As Long)
Dim SampleSizes As Variant
Dim Item As Long
SampleSizes = RoundSum(BedCapacity, SampleSum)
For Item = LBound(SampleSizes) To UBound(SampleSizes)
Debug.Print Item + 1, BedCapacity(Item), SampleSizes(Item)
Next
End Sub
Result:
1 22 12
2 18 10
3 20 11
4 16 9
5 19 11
Too much code to post here, but full code is for download at GitHub: VBA.Round
Two of the columns in Query A are labeled 2012 and 2011.
However, next year, the columns will be 2013 and 2012. This is because those columns are part of a crosstab where the name is done via the year() function.
Anyway, I am using a new query to add a column that subtracts the values in the two year columns, but I don't know how to refer to those columns dynamically.
e.g. I could easily add a column
Difference: [2012 Revenue] - [2011 Revenue]
But this would stop working next year.
Why don't you label them these columns to something a little more generic and use them like this
Difference:[This Year] - [Last Year]
Building on HelloW excellent suggestion, you could use as the Column Header of your Crosstab an expression like "RevYr" & (Year(Date())-Year(RevenueDate), which would evaluate to
RevYr0, RevYr1, RevYr2, etc...
Your difference would then become
Difference: RevYr0 - RevYr1
Edit:
Facing a similar problem using a crosstab, I found these 2 very interesting links:
http://allenbrowne.com/ser-67.html
http://www.access.hookom.net/DynamicMthlyCrosstabRpt.htm
I have a report which grabs a whole bunch of statistical data that represent system alarms.
I've made a drilldown style report by pulling back all the stats in a user selected date range and then I added a group on my alarm's codeId so I would have something to group on.
What I would like to do is have a count of the number of items within these groups by codeId. I plan to use the count as part of a concatenated string that makes up the whole group header. It basically says "Alarm Code # {codeId} - {Description} - Total: {Total}".
My issue is that to do a count in my query then I have to pre-group the data before it hits the report. And if I do that then I do not have my detail data to expand the group on. And running a summary and a detail dataset is a bit over my head but an option I might have to look into.
So I was hoping I could use a group variable to count the number of items contained within the group. Can anyone tell me a rough set of steps to try to pull that off?
Seems like using a Group variable here would make this more complicated than it needs to be.
Since you already have a group in SSRS, you can use the CountRows function. Put this expression into a placeholder, for example:
="Alarm Code #" & Fields!CodeID.Value
& " - " & First(Fields!Description)
& " - Total: " & CountRows()
Or, depending on size, you can add a correlated subquery to your SQL query:
SELECT
CodeID,
MyField,
MyOtherField,
(SELECT COUNT(*) FROM myTable t1 WHERE t1.CodeID = t2.CodeID) AS MyRowCount
FROM
myTable t2
This is not particularly efficient SQL, so if you are running this on hundreds of thousands of rows or more, I'd go with the first approach.