Change SQL table design for Power BI dataset - sql

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.

Related

Dynamic columns in reporting services for an SQL pivot table

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?

Why Excel pivot table does not retrieve data for all dates?

Time table in SSAS Cube has all correct dates. And Data source view also has the correct data for those dates. However why Excel pivot table does not retrieve data from the specific week? (3rd week in the year)
Only 3rd week data is being missed in Excel pivot table.
enter image description here
Could a filter in the pivot table be on by accident? Not in the data, but the table itself. Maybe a date got unticked? this could cause it.
example of pivot filter
It's probably unlikely, but it could be that there's no data in that week for the measure you've selected. Do you see the week if you browse the time dimension itself in SSDT?

Wild Card Character to extract all the columns in Sql Server Pivot column

While creating PIVOT table in Sql Server i need to mention the column in hard coded manner but now i have to write down all the columns. Now from my code you can see i can't predict what a month user might choose and i want to show that months all dates.
pivot
(
sum(column1)
for Date in (
[04-18-2014], [04-19-2014]
)
Here i have to mention that [04-18-2014], [04-19-2014] are the column names that i have to use. how can i extract all the columns whatever present in Date column like a wild card character or something else which can help me to solve this problem.

How do I create a summary data item in Cognos Report Studio?

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.

SQL Server : Querying Multiple Rows, Returning In One

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