The Transform Statement:
TRANSFORM Sum(January2015.txnamount) AS SumOftxnamount
SELECT January2015.txndate2, January2015.cbsaccno
FROM January2015
GROUP BY January2015.txndate2, January2015.cbsaccno
PIVOT January2015.txntypes;
gives output as below:
+------------+---------------+-----+-----+
| txndate2 | cbsaccno | A1 | A2 |
+------------+---------------+-----+-----+
| 01/01/2015 | 0021010392747 | 50 | 300 |
| 01/01/2015 | 0021010392891 | 100 | 200 |
+------------+---------------+-----+-----+
I want a fifth field (calculated field A1-A2)
which have values -250 and -100 for the sample data above.
Anyway to do that?
Thanks in advance.
Save the query you built (for example, PivotQuery). Create a new query that calls PivotQuery with the following SQL:
SELECT PivotQuery.*, [a1]-[a2] AS CalcField
FROM PivotQuery;
Related
This is type of my dataset:
| Date(dd/mm/yyyy) | Value |
|------------------|-------|
| 01.01.2018 | 50 |
| 01.01.2019 | 100 |
| 01.03.2019 | 200 |
| 01.05.2019 | 400 |
from this dataset i maked tablix:
| Date | 01.01.2018|01.01.2019 | 01.03.2019 | 01.05.2019 | Δ |
|-------|-----------|-----------|------------|------------|-------|
| Value |50 |100 | 200 | 400 |300 |
How to put into tablix change value(+300) between 2 dates: 01.05.2019 -01.01.2019?
I used construction with lookup function, but it doesn't work:
made dataset with 2 dates:01.05.2019 and 01.01.2019
=lookup(min(Fields!Date.Value,"dataset2"), Fields!Date.Value, Fields!Value.Value, "dataset1")
If you add a parent column group call for example colgrpYear and set the grouping expression to be something like:
=YEAR(Fields!Date.Value)
This will group by the year -- you can hide the column group header if you like.
Then set the calculation expression to ..
=Last(Fields!Value.Value, "colgrpYear") - First(Fields!Value.Value, "colgrpYear")
This will scope the expression within the just the year that the cell resides in.
Note The scope must be in double quotes and is case sensitive.
I need some help in achieving a functionality. The idea is to calculate the sum of duration for all distinct activities which the query is bringing. A couple of considerations
The query is not SQL, its FetchXML (Microsoft Dynamics 365).
Grouping is not done on Activity IDs instead Contact ID, and it has to be that way only.
Here is how the data looks like
| Contact ID | a.activityid | b.activityid | b.duration |
|------------|--------------|--------------|------------|
| A | a1 | act_1 | 15 |
| A | b1 | act_1 | 15 |
| A | c1 | act_1 | 15 |
Now, I'm trying to Sum(b.duration) and it gives me result as 45, but I want the sum as 15 because b.activityid is getting duplicated in the resultset.
In short Sum of duration for distinct b.activityid.
Can anyone help me out a little here?
I am trying to assign values to textboxes in SSRS but am running into a bit of trouble.
My dataset "dsStepInfo" groups and sums a number of rows together based on "ID", query below.
SELECT ID, SUM(Target) AS Target, SUM(Actual) AS Actual
FROM tblStepComplete
WHERE (CompleteID = #ParamID)
GROUP BY ID
And returns:
ID Target Actual
-------------------------------
| 10 | 44418 | 44418 |
-------------------------------
| 12 | 13193 | 13123 |
-------------------------------
| 22 | 1411 | 1411 |
-------------------------------
| 50 | 160 | 80 |
-------------------------------
| 52 | 68 | 34 |
-------------------------------
| 101 | 12120 | 12119 |
-------------------------------
| 105 | 875 | 868 |
-------------------------------
| 140 | 40 | 40 |
-------------------------------
| 560 | 2985 | 3418 |
-------------------------------
I want to assign cells in the grid in the picture to a certain ID. The Cell for tank 110 would always be the Target of ID=50 and Actual of ID=50 for example. Many of the IDs returned aren't going to be populated in the table, just the 10 displayed in this table. Is there any way to perform a SELECT, or equivalent in the textbox as an expression to get these specific values from the dataset?
You can use the Lookup function.
This should get the ID #50 and output its Target:
=Lookup(50, Fields!ID.Value, Fields!Target.Value, "DSStepInfo")
I think if it were me I'd just use a Case statement, something like
SELECT
Case [ID]
WHEN 10 Then 'Tank 50'
WHEN 12 Then 'Tank 120'
When 22 Then 'Tank 130'
WHEN 50 Then 'Tank 140'
When 52 Then 'Tank 150'
End As TankNo
,SUM([Target]) As Target
,SUM([Actual]) As Actual
FROM tblStepComplete
WHERE (CompleteID = #ParamID)
Group By [ID]
And then build your report using the values presented. Better would be an additional table that had the Tank names linked to the IDs you are pulling, but if you don't have that then the Case statement is fairly easy to maintain.
I want to create an application which one is summary the values of each column. I have a table like this:
Each rows contains one goods
Date | Company_Name | Order_cost | Weight |
2013-05-15| Dunaferr | 310 | 1200 |
2013-05-18| Pentele | 220 | 1600 |
2013-05-25| Dunaferr | 310 | 1340 |
and what I exactly need is a table or view which contains the totals for the weights column for each week which is supposed to be extracted from the date column!
Something like that
company_name | week1 | week2 | week3 | week4 ...
dunaferr | 35000 | 36000 | 28000 | 3411
pentele | 34000 | 255000 | 3341 | 3433
Is there any way to do this?
I would do this in two steps:
First step complete an sql query getting a summary with a sum for weight with a group by for yearweek
SELECT Company_Name, YEARWEEK(Date), sum(weight) FROM table GROUP BY Company_Name, YEARWEEK(Date)
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_yearweek.
Second step would be to process this into the required format in the application year.
If you absolutely have to do this in the database, then you are looking at implementing a pivot table, which has previously been covered here: MySQL pivot table
i'd like to generate some gantt-report (inside html table) with data from mysql table to my ci-view..
the view should be like this :
| name | week#1 | week#2 | week#3 | week#4 |
| wawan | 200 | 340 | 0 | 100 |
| wewe | 210 | 340 | 120 | 100 |
| elias | 200 | 360 | 0 | 170 |
weeks are distinct from field 'week'.
names are distinct from field 'user'.
numbers are sum(qtyfield) from table where user is 'name' during x week
i've tried this method, but the numbers (sum of 'qty' field) won't show :
fetch the weeks row to a table-header block inside a foreach loops -> done.
fetch the names row to a table-row block inside a foreach loops -> done.
the sum(qty) is query base on name in table-row and week in table-header -> ?
any idea how to do this? syntax help or just logic thought are appreciated..
thanks in advance..