I have a problem that i am not able to fix.
I have a table like this
i want the output to be like this (NOT this, look at the revised result image):
is this possible with T-SQL? maybe with Excel?
There are 140 categories and approx. 60.000 rows.
Edit:
Just to clarify. I want an amount column for every category column. So if there are 140 categories, i want 140 amount columns. If there is no amount for a given category, it just going to null or amount =0.
EDIT2:
Revised result:
You can use pivot and dynamic query to generate into columns.. I just gave a sample with 2 categories you can generate the complete list using your table
select * from #yourcustomer
pivot (sum(amount) for category_name in ([cat1],[cat2] --,all categories list generated based on yourtable..........
)) p
Related
I am using SSRS 2014. My end goal is to get a table that looks like the following:
Project Status # of Projects Oldest Project Avg Project Age
Status 1 27 82 16
Status 2 9 29 6
Status 3 13 112 25
Status 4 33 68 16
Status 5 1 63 63
Status 6 1 27 27
Grand Total 84 112 17
A table like this, including the grand totals, can be done in Excel using pivot tables (this is how the data was originally retrieved...manually...)
If I have the same source data in a table where my columns include projectStatus and projectAge, I could generate a query to get all but the grand totals in SQL:
SELECT projectStatus, COUNT(projectStatus), MAX(projectAge), AVG(projectAge)
FROM projects
GROUP BY projectStatus
If I wanted to add grand totals to that, I could do a UNION with the following query:
SELECT 'Grand Total', COUNT(projectStatus), MAX(projectAge), AVG(projectAge)
FROM projects
Note that the grand totals are calculated off of the entire dataset and not just the grouped data - this mostly applies to the average, because it just happens to work out for the COUNT and MAX columns.
Now, if I am trying to generate this above table in SSRS, it is easy to generate the above table sans grand totals using the former query. However, now how do I add grand totals?
I could instead try a different approach where I use a more generic dataset query like:
SELECT projectStatus AS statusCategory, projectAge AS daysInCurrentStatus FROM projects
And then use aggregate functions in my table and have SSRS do the aggregation itself and provide grand totals on the raw data. I get a new problem now. What is the correct way to set my table up? I am calling grouping by [statusCategory] as "Group1", using scoped aggregate functions like so:
And it correctly generates the grand totals, but now I have a new problem: it is showing the average for each row instead of just one cell per group/scope. Is this something SSRS is meant to do, and if so, how can I do it?
...
You need to mess around a little to get right layout, but you basically need a group header or footer to show the Group aggregates.
if you right click on the lines next to [statusCategory] and select Insert Row > Outside Group - Above it will create a group header for you. Then just add your aggregate expressions in the correct columns like =Count(Fields!projectStatus.Value) then you can just set Row Visibilty on the details row to hide if you dont want to see it.
you should end up with a layout similar to this.
with the middle row (detail) visibility set to false
You're on the right track. You have two Row Groups right now. All you need to do is remove the inner one because it's not grouped by anything. In other words, it's repeating for every row of raw data.
So the Row Group named "Details" - either remove it or in the properties click "Add" and group it by 1. That will collapse those rows and do what you were expecting.
I'm new to OLAP cubes. Can you directed in the right direction with small example.
Let's say I have table "transactions" with 3 columns: transaction_id (int), date (datetime), amount (decimal(16,2)).
I want to create a cube and then get data with MDX query for SSRS report.
I want report to show something like:
Ok. I know i can have fact table with amount and date dimention (date->month->year).
Can you explain what to do in order to get this result (including how to write MDX query). Thanks.
Can someone explain why I get amount of full 201504 and 201606 months even if I specified exact range with days?
SELECT
[Measures].[Amount] ON COLUMNS
,[Dim_Date].[Hierarchy].[Month].MEMBERS ON ROWS
FROM
[DM]
WHERE
(
{[Dim_Date].[Date Int].&[20150414] : [Dim_Date].[Date Int].&[20160615]}
)
Something like below, change the query accordingly :)
SELECT
{ [Date].[EnglishMonthName].[EnglishMonthName]} ON COLUMNS,
{ [Date].[DateHierarchy].[Year].&[2015],
[Date].[DateHierarchy].[Year].&[2016] } ON ROWS
FROM [YourCubeName]
WHERE ([Measures].[amount])
So you want someone to show you how to create a multi-dimensional cube from scratch and report on it in a single answer...? Start here and work through the lessons
hoping someone can help with my Excel query.
I want to use the quartile function (or similar, could use percentile if that's easier). I have data in a column but I want to limit the data I use from that column.
I have job departments in column A, people's salaries in column B (and other data in the other columns e.g name).
I want to use my one main data list (c. 2,000 rows) to pick out the quartiles for the 10 or so depts I have but I don't want to have to make 10 specific lists to calculate the quartile of each dept.
Is there an option to use a countif or similar function so that I can have a drop down list of my 10 depts and depending on what dept I select my summary table will show the quartiles relevant for just that dept?
Thanks
Use an array formula =quartile(if(A1:A1000=C2,B1:B1000),.75) press control + shift + enter after entering the formula. Note: C2 = the department which quartile you are calculating.
I have a following employee table value as below :
name | cost
john | 1000
john | -1000
john | 5000
when we add the cost column total will be 5000.
I need to print only the 3rd row in BIRT report, since the 1st and 2nd row get cancelled out each other.
I'm stuck at filtering the table for above scenario.
Couldn't you just solve this using SQL like
select name, sum(cost)
from employee
group by name
order by name
?
Or do you just want to exclude two rows if they have exactly the same cost, but with different signs? Note that this is actually something different, take for example the three rows [ john|1, john|2, john|-3 ]? In this case, a pure SQL solution can be achieved using the SQL analytic functions (at least if you are using Oracle).
Elaborate your question. Its not clear if these are columns or rows.
If These are columns:
Create a computed column in your dataset
In Expression builder of that column add/sub values using dataSetRow['col1'] and dataSetRow['col2']
Add only that computed column to your table.
If these are rows
Select rows you don't want to print
Go to properties tab
Find Visibility property and click on it
Check Hide Element option
I have a tablix with the following details:
Apple
Apple
Apple
Mango
Mango
I want to have a subtotal cell having:
Apple: 3
Mango: 2
How to do this without counting the items by id?
Thanks in advance!
Couple of approaches you can use, You can write a query that generates the row count for you - not knowing your data here is an example
SELECT Fruit, COUNT(Fruit) AS NoFruits FROM (SELECT Fruit , 1 AS FruitNo FROM dbo.xxxtblFRUIT) AS a GROUP BY Fruit
Or in SSRS tablix you can create a group and do a count in there.
****UPDATED*****
From what I under stand from your data you can add a row group outside your current group and do the count in that.
Thats what would be returned.
I'm assuming you're still looking for answer to this...
Could you try adding a new table and then using Row Groups to group the data by the values? If we're using the data set from above, you could set the group to "Fruits." You would want your table to have at least two cells, one cell would contain the fruit (Fields!Fruit.Value) and the second cell would have (Count(Fields!SomeOtherColumnInYourDataset.Value). Does this make sense?