Subtracting row values in Cognos - cognos

I have the following report:
Id Product Revenue Month
1 A 302 jan
1 A 342 feb
1 A 133 mar
For this report, I need to find the difference in revenues for months, i.e difference in revenue from Jan to Feb and feb to march.
I want to add another column like this:
Id Product Revenue Month Profit
1 A 302 jan
1 A 342 feb 40
1 A 142 mar -200
I can write a case statement for it and create a Calculated field but I don't know how to refer the rows to do my subtraction. Can someone help me with this.

What happens when you try running-difference([Revenue])?

Related

Excel not sorting numbers correctly on pivot table

It's as the title says, my excel pivot table is not sorting numbers corretly.
When I create the pivot table from my dataset, the goal is to have the data sorted by year, week number, and the Keys sorted by the PM_Value (decreasing order) as shown here. The "PM_Value" column is a Calculated Field.
Year
WeekNum
Key
Value 1
PM_Value
Value 2
2023
1
2022-SFS-R757-L05 VAC1
5.777
833
6.936
2023
1
2022-GS7-R125-L05
4.407
833
5.292
2023
1
2022-GS7-R008-L05 VAC
5.347
833
6.421
2023
1
2022-SFS-R735-L05 VAC1
5.757
830
6.938
2023
1
2022-GS4-R007-L06
13.431
829
16.195
2023
1
2022-SFS-R804-L05 VAC1
5.646
829
6.811
2023
1
2022-GS7-R083-L06
4.983
749
6.656
2023
1
2022-GS7-R107-L06
4.941
749
6.600
The problem is that the PM_Value column has zeroes (or possibly errors shown as zeroes), and these values are not sorting correctly. Currently de sorted pivot table is like de one below.
Year
WeekNum
Key
Value 1
PM_Value
Value 2
2023
1
2022-SFS-R757-L05 VAC1
5.777
833
6.936
2023
1
2022-SFS-R735-L05 VAC1
5.757
830
6.938
2023
1
2022-GS7-R038-L06
5.055
749
6.753
2023
1
2022-GS7-R081-L06
5.081
748
6.795
2023
1
....
...
...
...
2023
1
2022-GS7-PRJ52-L12
4.641
33
139.684
2023
1
2022-GS7-PRJ53-L12
4.190
29
144.750
2023
1
2022-SFS-R715-L06 RGD
0
0
0
2023
1
2022-SFS-R719-L06 RGD
0
0
0
2023
1
2022-SFS-R789-L06 RGD
0
0
0
2023
1
2022-GS4-R054-L05 VAC
14.131
811
17.416
2023
1
2022-GS4-R015-L06
15.052
802
18.776
2023
1
2022-GS4-R031-L05 R2
4.856
789
6.156
2023
1
2022-GS4-R058-L06
12.639
731
17.290
I already tried to deactivate de "custom lists" sorting check box on the pivot table options, changing the order of the sort (i.e. Year/Month/Key, Key/Year/Month, etc) but nothing makes the zeroes stay on the bottom of the sorted column.
Has anyone experienced anything like that and could help me?
I don't know if the correct procedure is to delete the question or not (If it is, can any moderator delete it please? sorry). But while I was writing I thought of a solution, and if anyone has this problem here it is:
The problem was that the calculation of "PM_Value" is a division, and some of the zeroes were DIV/0 errors showing as zeroes and these errors that were messing with the sort. I used a IFERROR(calc,0) on the Calculated Field and the problem disapeared!

Convert Daily dates to weekly using a specific first day of the week

I am currently working on grouping/aggregating data based on date range for a weekly plot.
Below is how my dataframe looks like for Daily data:
daily_dates
registered
attended
02/10/2022
0
0
02/09/2022
0
0
02/08/2022
1
0
02/07/2022
1
0
02/06/2022
20
06
02/05/2022
05
03
02/04/2022
15
12
02/03/2022
10
08
02/02/2022
10
05
The first day of the week I'd want is Sunday.
My current code to perform weekly group is:
weekly_df = weekly_df.resample('w').sum().reset_index()
The output I am desiring is:
weekly_dates
registered
attended
02/06/2022
22
06
01/30/2022
40
28
A bit of explanation about desired output - the reason for 02/06/2022 & 01/30/2022 is that both these dates are start date of that respective week which is a sunday. And for the week of 01/30/2022 only 02/05/2022|05|03, 02/04/2022, 02/03/2022, 02/02/2022 dates are considered as those are the one's in the daily dataframe.
My current implementation follows the instructions provided here.
I am looking for any suggestion to achieve my Desired Output
Try:
df.resample('W-SUN', label='left', closed='left').sum().reset_index()
Output:
daily_dates registered attended
0 2022-01-30 40 28
1 2022-02-06 22 6

Conditional Cumulative Sum based on multiple columns

I have a simple inventory table in excel that looks like this:
Number of Items | Date Incoming | Date Out
-------------------------------------------------------
10 | 1 Jan 2018 | 30 Jan 2018
30 | 15 Jan 2018 | 1 May 2018
20 ! 1 Feb 2018 | 15 Mar 2018
I would like something that can give me the the total number of items that are present in the inventory at each date, that is:
1 Jan 2018 | 10
15 Jan 2018 | 40
30 Jan 2018 | 30
1 Feb 2018 | 50
15 Mar 2018 | 30
1 May 2018 | 0
What I was thing is some sort of cumulative sum where the number of items are added at "Date Incoming" and substracted at "Date Out".
Can you help me? I would prefer to avoid macros but even a vba solution if fine.
For a given date, you can do:
=sumif(#DateIn, "<="&#CellWithGivenDate, #NumberOfItems) - sumif(#DateOut, "<="&#CellWithGivenDate, #NumberOfItems)
With #NumberOfItems, #DateIn, and #DateOut being columns 1 to 3 of your sample, and #CellWithGivenDate being the relevant cell in column 1 of your expected result sample.

Merging and Adding Data in Excel Worksheets

I have 8 sheets of data (from Dec 2014 to July 2015, separated month wise). Each sheet contains monthly data (e.g. Dec 2014 sheet contains data of dec 2014 in three columns namely AC #, Name, Amount).
Dec 2014 Contains Data as Mentioned Below:
A/C # Name Dec 2014
A12 ABC 100
A13 CBA 200
A14 BCA 300
Whereas January 2015 contains data as below
A/C # Name Dec 2014
A12 ABC 5
A13 CBA 300
*A15 IJK 900*
All sheets contains mostly same data but some additional data based on customers added in that month or amount. E.g. January 2015 may contain an additional client a/c #, name and amount of January 2015 as marked above.
I want a consolidated sheet of data where all data is arranged as below:
A/C # Name Dec 2014 Jan 2015 Feb 2015 Mar 2015 Apr 2015
A12 ABC 100 5
A13 CBA 200 300
A14 BCA 300 0
A15 IJK 0 900
I would suggest connecting to the worksheets using ADODB. Then you can issue an SQL statement that will merge the records together.
This could be run from a VBScript, or from Excel.
For a similar strategy, see here.

Parse CSV file with some dynamic columns

I have a CSV file that I receive once a week that is in the following format:
"Item","Supplier Item","Description","1","2","3","4","5","6","7","8" ...Linefeed
"","","","Past Due","Day 13-OCT-2014","Buffer 14-OCT-2014","Week 20-OCT-2014","Week 27-OCT-2014", ...LineFeed
"Part1","P1","Big Part","0","0","0","100","50", ...LineFeed
"Part4","P4","Red Part","0","0","0","35","40", ...LineFeed
"Part92","P92","White Part","0","0","0","10","20", ...LineFeed
...
An explanation of the data - Row 2 is dynamic data signifying the date parts are due. Row 3 begins the part numbers with description and number of parts due on a particular date. So looking at the above data: row 3 column7 shows that PartNo1 has 100 parts due on the Week of OCT 20 2014 and 50 due on the Week of OCT 27, 2014.
How can I parse this csv to show the data like this:
Item, Supplier Item, Description, Past Due, Due Date Amount Due
Part1 P1 Big Part 0 20 OCT 2014 100
Part1 P1 Big Part 0 27 OCT 2014 50
Part4 P4 Red Part 0 20 OCT 2014 35
Part4 P4 Red Part 0 27 OCT 2014 40
....
Is there a way to manipulate the format in Excel to rearrange the data like I need or what is the best method to resolve this?

Resources