I am having trouble with a pivot table that changes the amount of columns depending on the data, so I want to show a "dynamic table" in SSRS according to my SQL table. Any idea of what I can do to show that pivot table in SSRS?
Related
I have a SQL table in the following format that I would like to use as a dataset in PowerBi:
I am trying to convert it into a condensed table like this:
Does anyone know how to go about this whether it is as a SQL script or in Power BI?
In the query editor, select all of the month columns (Jan - Dec) and choose Unpivot Columns under the Transform tab.
Once it's unpivoted, just filter out the zeros.
I have a customers table that houses contacts. Each contact is added as another row to that customer.
I want to create my query so that I can create columns for contact1, contact2, contact3 and so forth. What's the best way to do this?
My rows are dynamic and I have been looking into unpivot and pivot but I'm not sure how I would build that into my query as I have a few joins and other data in the query.
SQL Fiddle example
Dynamic pivot query is what you need. See this:
http://buysql.com/mysql/14-how-to-automate-pivot-tables.html
and this:
SQL Server dynamic PIVOT query?
Say I wanted to group all my metrics that I have in my values in my pivot table(including all added calculated fields) into one field to be able to use in the Report Filter.
So I want all those values in a drop down to be able to select a metric and it populates my pivot table below.
Is that possible with VBA Code? Am I explaining clearly?
I am working on a Cognos Report Studio Version 10 where I have to convert SQL code into Data Items. I have all the Columns required in the package to drag as Data Items in the query but I am stuck where there's calculated fields. This is one of them
NET_ORIG_AMT derived from
(ORIG_ AMT) – (PARTICIPATION_ORIG_AMT)
ORIG_AMT was derived from a simple IF THEN ELSE function and could be easily created as a calculated data item.
But PARTICIPATION_ORIG_AMT is coming from this SQL code:
SELECT LEAD_ACCT,
PART_FLAG,
SUM (ORIG_AMT) AS PARTICIPATION_ORIG_AMT,
FROM TableName
GROUP BY LEAD_ACCT, PART_FLAG
HAVING PART_FLAG = 'Y'
How do I create a Data Item for PARTICIPATION_ORIG_AMT?
Pl note: I have LEAD_ACCT, PART_FLAG fields as calculated fields in the Query.
Can you help me understand how to write SUM (ORIG_AMT) AS PARTICIPATION_ORIG_AMT Group by LEAD_ACCT, PART_FLAG in Cognos Report Studio?
The equivalent in a Cognos expression would be:
total([ORIG_AMT] for [LEAD_ACCT],[PART_FLAG])
3 choices:
Create a separate query in Cognos specifically for PARTICIPATION_ORIG_AMT. Join this query to your primary query on the appropriate fields and bring this in.
Create a query subject for PARTICIPATION_ORIG_AMT within the model itself, and do the above in RS as described above. Preferred method if you are re-using this data item across reports.
Create a view in SQL which takes care of all of this special logic.
Problem
We are currently working with some data which is stored as in the screenshot below. We are using this to display information in a C# application. The only way we can get the application to work as needed is to have the information in one single row.
We have tried some methods on Display multiple rows and column values into a single row, multiple column values to no avail.
Desired output
We require each row with the same date and vehicleID to be on the same row to be output from our stored procedure.
Any help would be greatly appreciated. Cheers.
if I understood correctly, you don't know how many unique date/vehicle_id combinations there are in the data. hence you can't just do a pivot over a set list of values.
in this case, you would need to build up a list of the date/vehicle ids dynamically, and then pivot over that list.
please check out the following examples involving dynamic SQL and pivot tables:
PIVOT in sql 2005
SQL Server : dynamic pivot over 5 columns
Pivot Dynamic Columns, no Aggregation
https://www.simple-talk.com/blogs/2007/09/14/pivots-with-dynamic-columns-in-sql-server-2005/
SQL Server dynamic PIVOT query?
Dynamic Pivot Columns in SQL Server
SQL Pivot Query with Dynamic Columns