cognos: Pick up the initial value for every row of a crosstab - cognos

I have a requirement in which i have to pick up the initial value of each row in a crosstab..
My crosstab looks like this
value 1960 1970 2010 2011
aus 10 5 11 6
eng 5 2
bra 11 4
ind 8 11
i have to add another column which picks up the initial value for every row based on the year..
so the result should look like this.
value 1960 1970 2010 2011 initialValue
aus 10 5 11 6 10
eng 5 2 5
bra 11 4 11
ind 8 11 8

You should be able to use the minimum() function to determine the lowest value for year and then return the value corresponding to that. The expression for the initialValue data item would be something like:
total(
CASE
WHEN [Year] = minimum([Year] for [Language])
THEN [Value]
ELSE 0
END
for [Language])
We get the lowest year for the specific language in the data set using the minimum() function using the for clause to define the aggregation level. If the year of the row matches this number, we output the value, otherwise we output 0. We then total everything up for each language which should give us the value for the lowest year.
This solution assumes that the numbers displayed in your crosstab are totals of lower-level row detail. If the aggregate is something different, such as average or count, the wrapping summary function should be changed accordingly.

Related

Excel: how to average with condition

We have an Excel sheet in which we collect some monthly data.
Each line contains a date and some value (in my boiled-down example here the date is always the first of each month and the values are [1..n]).
I am now trying to calculate an average of the values but not from ALL values but only those from the last quarter (i.e. where Date is >TODAY()-90).
TODAY() at the time of this writing is Jan. 30th, 2023, so I would expect the result to be 12, i.e. the average of the values for the last 3 months (11, 12, and 13).
A B
1 Date Value
2 01.01.2022 1
3 01.02.2022 2
4 01.03.2022 3
5 01.04.2022 4
6 01.05.2022 5
7 01.06.2022 6
8 01.07.2022 7
9 01.08.2022 8
10 01.09.2022 9
11 01.10.2022 10
12 01.11.2022 11
13 01.12.2022 12
14 01.01.2023 13
15
16 Avg. last 3 months:
17 #VALUE! <-- =AVERAGE(IF(A2:A14>(TODAY()-90);B2:B14;0))
18 #DIV/0! <-- =AVERAGEIF(A2:A14;">(TODAY()-90)";B2:B14)
I tried several approaches using AVERAGE(...) and AVERAGEIF(...) functions as shown above (and also several other variants) but I could not manage to get this working. All I ever get are error messages like #VALUE! or #DIV/0! :-(
Any idea how I can convince AVERAGE(IF) to only consider those values where the date is >today-90 days?
As per my comment:
=AVERAGEIF(A2:A14,">="&TODAY()-90,B2:B14)
Where the ampersand calculations operator is just a less-verbose way to concatenate different values. Here the 2nd parameter takes a string so using both parts on the left and right of the operator we create a value such as ">=12345".

How to combine SUMPRODUCT with an INDEX and MATCH formula?

Note, I have edited my original question to clarify my problem:
As the title suggests, I am looking for a way to combine the SUMPRODUCT functionalities with an INDEX and MATCH formula, but if a better approach exists to help solve the problem below I am also open to it.
In the below example, imagine that the tables are on different sheets. I have a report that has the sales of each ID in the rows and each month in the columns (first table). Unfortunately, the report only has IDs and not the region they belong to, but I do have a look up table which labels each ID with their respective region (second table):
A
B
C
D
1
ID
January
February
March
2
1
10
5
20
3
3
5
5
10
4
7
0
10
5
5
14
10
25
5
6
25
5
10
10
7
27
10
10
10
8
44
5
5
5
A
B
1
ID
Region
2
1
East
3
3
East
4
7
Central
5
14
Central
6
25
Central
7
27
West
8
44
West
My goal is to be able to aggregate the sales by region as per the result below. However I would only like to show sales data that belong to the month that is shown in cell D2.
Goal:
A
B
C
D
1
Region
Sales
February
2
East
10
3
Central
45
4
West
15
I have used the INDEX and MATCH combination to return a single value, but not sure how I can return multiple values with it and aggregate them at the same time. Any insight would be appreciated!
You may just use:
=SUMPRODUCT((Sheet1!B$1:D$1=D$1)*(Sheet1!H$2:H$8=A2),Sheet1!B2:D8)
Remember, SUMPRODUCT() could be quite heavy processing huge data, therefor to combine INDEX() and MATCH() is not a bad idea, but let's do it the other way around and nest the latter two into SUMPRODUCT() instead =):
=SUMPRODUCT(INDEX(Sheet1!B$2:D$8,0,MATCH(D$2,Sheet1!B$1:D$1,0))*(Sheet1!H$2:H$8=A2))
Another option using SUMIF+INDEX+MATCH function as in
In "Sheet2" B2, copied down :
=SUMIF(Sheet1!H:H,A2,INDEX(Sheet1!B$1:D$1,MATCH(D$2,Sheet1!B$1:D$1,0)))

count and sum function not properly working

I am working in excel and for some reason my sum or count function is not working properly. Or, perhaps I am not using the correct function or in the right way.
A B C D E F G H
February Max March Max
1 28
2
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
IF(SUM(E:E>0),31,"")
I have the above columns, I want the Max columns to show a specific number only if there is data in their respective month column. February has data, so it shows 28. March does not have any data so it shows no max. I need to look at the entire column or at least a large area (row 2 to row 2000).
The issue I am having is that if I do not have a value in the first row, but do have values in later rows, the sum or count function will to recognize that and will return zero.
A B
February Max
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
I have tried both sum and count functions, neither are giving me the results I want. I have also tried making >= 1. I found from StackExchange that someone was having a similar problem and a solution was to change the cell format to a number. That did not work either. Any suggestions?
Per my comment, you could use COUNTA() which checks if a cell is blank.
While it doesn't answer the technical reason SUM/COUNT isn't working, it should work for your intended purposes.
=IF(COUNTA(A:A)>0,28,"")

Sum of Vlookups advice

I have a column "Uni"
E.g.
Person Uni Round 1 Round 2 Total Rank
Leia Notts 5 5 10
Hailey Notts 6 5 11
Bobby Bath 8 1 9
James Liverpool 9 1 10
Then another table:
University Total Score Rank
Notts =sum(vlookup(...))
Bath =sum(vlookup(...))
Currently, my formula returns the 'first' lookup of the keyword - e.g. for notts, it returns '10' - rather than looking up the 10 and the 11 and summing them.
How do I make it lookup and sum both values?
My current formula is =sum(vlookup(S7,B$3:Q$40,15,FALSE)) where S7 is "Notts", range, index column 15 is "total score"
There's about 8-10 of each university.
Vlookup only returns one value, you can't sum over that.
Maybe use instead something like
=SUMIF(B$3:B$40,S7,$P3:$P40)

Excel formula to Increment every after X Number of Years

I would like to Add an Increment of One on Every X Year Interval
For Example if X = 3 Then the Following Data should be
SG Last Year
5 2010
4 2014
3 2015
6 2016
Would result to
Grp Last Year 2016 2017 2018 2019 2020
5 2010 6 6 6 7 8
4 2014 4 5 5 5 6
3 2015 3 3 3 4 4
6 2016 6 6 6 7 7
So the First Record the Candidate is in group 5, from 2010, in 2016 I would like to calculate if the candidate has a span of at least 3 years if so, push him to 1 upper group which is 6. The Same Candidate will go through n Number of years and every 3 years (X Number of Years) would increment their group till we reach to 1 and continues with 1 without any increment. Thus is the same example since we increment in 2016, the candidate would have the same group for the next 3 years and only in 2019 would we increment again and so on.
I would like and excel formula or process which I could use for the data set proposed
You were almost there.
LY = Last year (that static cell in each row);
AY = Active year (the column for which you are calculating),
G = group (start value),
PR = previous result (for prev year),
R = result (what you want to get),
X = year interval`
You can use one formula for first year (2016) and another for the rest, so you can use previous value PR, not initial group G.
Obviously LY stays constant for the row.
R = IF (( (AY-LY) \ X)==0 , PR+1, PR) - change when mod is 0.
Use #3 formula for all the years except first column (2016).
For first column (2016) instead of PR you should use G.
To have a constant cell, you write in form of $A$1 (for G)
For constant row you write in form of C$0 (for AY)
Your formula was almost correct. And you need to set the values constant where they need to be.

Resources