excel - is it possible to group dates in a column in pivot table? - pivot-table

I have a table where the columns are months. I want the sum of values grouped by 3 months. I was wondering if this is even possible as the group button is grayed out.
January February March ...
999 999 999
999 999 999
999 999 999
the output should look like
January-March ...
8991

Related

Consecutive day count with total

Is there a way to show if the days go consecutively? I need to show a total for when the date is 5 consecutive.
The data is shown below. Could I put a date range for April like: date between 2019-04-01 and 2019-05-31 and show the DATEPART(WEEK,date) for the first date of the 5 consecutive.
I'd like to show the total of 5 consecutive days like below. It skips the week that did not have a date for 5 consecutively.
Week Total
21 7.50
23 7.50
Something like this should work for you.
SELECT DATEPART(WEEK,[Date]),SUM([Dollar])
FROM [dbo].[TEST]
GROUP BY DATEPART(WEEK,[Date])
HAVING COUNT(DATEPART(WEEK,[Date])) >= 5
Here is a SQL Fiddle.

Pivot or unpivot a table

I have a table in SQL that I need to pivot or unpivot (not sure which). The table consists of days (as represented by workdays##1, workdays##2, workdays##3,etc.) The values under these days are a business day value for the month. Other columns in this table are Company, Year, Monthnum which should remain as columns. So it looks something like this:
SQL table
Company Year Monthnum workday##1 workday##2 workday##3 workday##4
US 2016 8 1 2 3 4
I need the workday##'s (renamed as day of month and substringed to just the number portion) to pivot to rows and the values under them to be put in one column with the header businessday. Future
Company Year Monthnum Dayofmonth Businessday
US 2016 8 1 (workday##1) 1
US 2016 8 2 (workday##2) 2
US 2016 8 3 (workday##3) 3
US 2016 8 4 (workday##4) 4
This table represents the year and month and the number of business days per month. From this I will be doing some month to date calculations against sales goals on a daily basis.

SQL Query-Multiple date ranges

I want to fetch some data from DB by giving multiple date ranges. Example,in February I want to get weekly report from a table in this order Feb 01 to 07, Feb 07 to 14, Feb 14 to 21, Feb 21 to 28 and Feb 28 to Mar 01. In DB the records are stored in a daily wise not in weekly wise. I want to cluster it as weekly wise and calculate sum then show the result. Please help me if you know this case.
For clear cut view, consider 3 tables & its columns.
Table A:id,timestamp (comment-data is inserted daily)
Table B:id,fruits
Table C:id,fruits_type
Result:
fruits_type count(id) timestamp
apple 3 01-02-2016 to 07-02-2016
orange 5 01-02-2016 to 07-02-2016
pineapple 8 01-02-2016 to 07-02-2016
apple 4 07-02-2016 to 14-02-2016
orange 5 07-02-2016 to 14-02-2016
Conditions:id should match among 3 tables;fetch data by providing group by fruits_type and timestamp should be in weekly wise.
Please help if you know this
To get the sum of all values between two dates you would do it like this:
SELECT SUM(Column1)
FROM Table1
WHERE Date1 BETWEEN '2/1/2016' AND Date1 <'2/7/2016'
If you want to make it more flexible and have the query get the last week's sum you can use the DATEADD function to lag by one week:
SELECT SUM(Column1)
FROM Table1
WHERE Date1 BETWEEN DATEADD(week, -1, GETDATE()) AND Date1 < GETDATE()
If you want the result set to include a row for each week, you can use UNION to merge the queries.

T-SQL Pivoting approach

I have a View that has a structure similar to the following:
Id Name State ZipCode #Requests AmtReq Price Month Year
1 John IN 46202 203 33 $300 1 2015
1 Jane IN 46202 200 45 $100 2 2015
...
Queries require reports to be generated for given quarters (1st quarter will include the first three months ...) grouped by state
The result should look like this:
Ist Quarter ...
January February ...
State ZipCode #Requests AmtReq Price #Requests AmtReq Price ...
IN 46202 203 33 45 200 45 100
I feel that this can be done using pivoting but I do not have experience with it. I tried with single column pivoting and had some success, but not in this scale.
Another approach would be to create a stored procedure that will generate the data for me and then just fix some formating (e.g., the first two rows) in the client. Any suggestions on how to approach this problem?
I am using SQL Server as a DBMS.
If you have MS Excel on your machine then you can export the view to Excel and summarize it to a pivot table. From there you can create table and diagrams as you needed.

SUM of 2 Columns using Crystal Report in VB.NET

My table name is "accounting"
it has two columns named "Debit" and "Credit"
Is it possible to have the sum of these two columns?
example:
INPUT:
Debit Credit
200 + -100
300 + -300
500 + -400
-------- ----------
1000 -800
I want it to appear like this in my Crystal Report:
Debit Credit TOTAL
200 -100 100
300 -300 0
500 -400 100
-------- ---------- ---------
1000 -800 200
I dont know what FORMULA I should use in Crystal Report
it is good if you this done in sqlserver as add a column with summary like
select
Debit, Credit, Debit+Credit as Total
from yourtable
If you wish in crystal report side, then also it is possible.
Add one variable and write this as below and put near this fields in detail section.
{#yourtablename.DebitField} + {#yourtablename.creditField} //I forgot the syntax, please change aproopriate.
Adding Sum of fields of two tables giving strange result in Crystal Report
http://vbcity.com/forums/t/154231.aspx

Resources