'Select All' Parameter not working - stored-procedures

Posted as a new question
The report is working ok in regards to selecting one country and seeing the different data within the 12 or 36 months date range.
The problem comes when I 'Select All' countries. What I want is the totals of all the countries to be represented on the graphs.
this is what the output is
country yyyy-mm Population Employed 12months 36months
uk 2016-06 56 43 y y
france 2016-06 40 22 y y
Germany 2016-06 73 32 y y
uk 2015-06 45 10 n y
france 2015-06 30 11 n y
Germany 2015-06 76 56 n y
AND SO ON......
All help appreciated, thank you.

Based on what you've described I think something like this will work for you
You are correct that you need two parameters: one for the country, the other is the period. For this second parameter specify two entries in the report designer. Give them the labels '12 months' and '36 months' and values or 12 and 36 respectively. Now change your dataset query as shown in the example below (obviously my table/column names won't be the same as yours)
select country, [yyyy-mm], Total
from #datatable
where country = #country
and ((#period = 12 and [12months] = 'Y') or (#period = 36 and [36months] = 'Y'));
The last line is where the magic happens. By testing the value of the #period parameter in the where clause we can make parts of the clause conditional.

Related

How can I perform a SUM calculation for unique values in a particular column in Tableau?

I am trying to sum the autonomy of all unique car models in Germany.
Key
Car model
Country
Color
Autonomy (miles)
1
ID3
Germany
Green
340
2
Polestar 2
Sweden
Yellow
335
3
EQS
Germany
Blue
450
3
EQS
Germany
Red
450
The answer should be: 340+450=790
450 should only be considered once because Key=3 is a unique identifier (Car model) even though the colour is different.
I tried doing that using INCLUDE/FIXED LOD expressions but I am doing something wrong.
Try below solution!
{FIXED [Autonomy] : MIN([Autonomy])}

How to replace arbitrary values of a variable with sequential values?

<For example:
a variable has values 1 2 3 5 10 11 12 13 14 20 21 ....
I want to replace it with 1 2 3 4 5 6 7 8 9 10 11.....
I was using this command but is not giving, the desired results:
old variable=district
I want to replace value with the correct sequential values>
levelsof district, local(district_new)
foreach i in `district_new'{
replace district= mod(_n-1,707)+1
}
Not fully sure what you trying to do, but is this a solution to what you are trying to do:
sort district
replace district = _n
This will replace the values in district with 1 for the lowest current value, 2 for the second lowest value etc. This might not be a good solution if your variable may have duplicates.
I agree with #TheIceBear but more can be said that won't fit easily into comments.
The particular code posted boils down to a single statement repeated
replace district = mod(_n-1,707) + 1
as that action is repeated regardless of the values of district. In a dataset with 707 or fewer observations, that in turn would be equivalent to
replace district = _n
as #TheIceBear points out. If there were duplicate observations on any district, this would definitely be a bad idea, and something like
egen newid = group(district), label
would be a better idea. For more, see https://www.stata.com/support/faqs/data-management/creating-group-identifiers/

select less than and replace with value in column A

I have a table with a few thousand rows and columns, it looks sort of like this
this:
ID Distance1 Distance2
1 102 101
2 101 100
3 100 99
4 99 98
5 98 97
...
I would like to select all values/distances in columns B and C that are less than 100 and replace them with the value in column A (their ID number).
All distances above 100 I want to delete. The real table has several thousand columns. How can I do this?
I have tried using search and replace, and conditional formatting where I have tried creating new rule using Index + Match but I encounter errors.
Assuming ID is in A1 of Sheet1, Copy the headings row into A1 of a new sheet and in B2 of that sheet:
=IF(AND(Sheet1!B2<100,Sheet1!B2>0),Sheet1!$A2,"")
Copy across and down to suit, Select the new sheet, Copy, Paste Special, Values over the top.
This above treats 100 as more than 100 and assumes no 0 or lesser values.

Formula to condtionally sum an array of values from one sheet to give totals on another

I have two sheets, connected by ID, which contain details of events and charges.
Sheet1 (breakdown of charges):
[Oh, just discovered I'm not allowed to include screen shots. I apparently need 10 reputation points. Not sure how to show you my spreadsheet now...]
ID DBF PCC Extras
1 200
1 100
3 200
4 350
4 250
4 75
4 25
7 100
[Sorry this will probably look horrible, I can't figure out how to include a spreadseet snippet without using an image. I had 3 imaage all prepared ready.]
Sheet2 (indentification and summary information):
ID Type Name
3 MON Edwards
7 REC Smith
4 WDG Jones
1 FNL West
8 WDG Richards
9 WDG Morrison
11 INT Gray
I am trying to add three additional columns to sheet 2 so that it shows a summary of the charges for each event. I would the charges information to update automatically in sheet2 as detail is added to sheet 1.
The resulting sheet2 will look like this:
ID Type Name DBF PCC Extras
3 MON Edwards 200
7 REC Smith 100
4 WDG Jones 350 250 100
1 FNL West 100 200
8 WDG Richards
9 WDG Morrison
11 INT Gray
As data for ID 8, 9 and 11 is added to sheet1, the summations should automatically appear in sheet2.
I have been trying to create an array formula to put in sheet2:B2, something like this:
=QUERY('Log Items'!A:F, "select sum(C), sum(D), sum(E), sum(F) where A="&A:A, 0)
This produces the correct result for ID 1 but it stops there and I'm not sure why. Also, despite my 0 as the third parameter, the header row is output.
I tried encapsulating the above in an ARRAYFORMULA but get a parse error.
I have also tried various combinations of ARRAYFORMULA, SUM and IF but not got anything that works. For example:
=ARRAYFORMULA(SUM(IF('Log Items'!A:A=A:A,'Log Items'!C:E,0)))
This gives #N/A "argument out of range", which I don't understand.
Although I've been working with Excel for a while, I'm really new to Google's Array formulas but have mananged to use them successfully in other parts of my spreadsheet and found them really powerful.
If anyone could help me with this, I would be very grateful.
In Sheet2!D2:
=ARRAYFORMULA(IF(A2:A,MMULT(N(A2:A=TRANSPOSE('Log Items'!A2:A)),N('Log Items'!B2:D)),))
Note: the N() functions have become necessary with different coercion behaviour in the new version of Sheets. They can be omitted in the classic version.
MMULT usage

get the total value base on month

i'm trying to get the total of value bas on month like this.
=SUMPRODUCT(MONTH($A$2:$A$10)=MONTH(C2);($B$2:$B$10))
have even try
=SUMPRODUCT(--(TEXT($A$1:$A$10,"yyyy-mm")=C2);$B$1:$B$10)
but all i get is Zero.
here is some sample
Column A b c d f g
2012-10-02 45 2012-10 45 2012 229
2012-09-05 45 2012-09 100 ect.
2012-09-03 55 2012-08 84
2012-08-25 84 ect.
etc.
ect.
thx in advance
with Excel 2010, you have the power of SUMIFS.
I would rewrite the formula as:
=SUMIFS(B:B;A:A;">="&DATE(YEAR(C2),MONTH(C2),1);A:A;"<"&DATE(YEAR(C2),MONTH(C2)+1,1))
which translates to:
Sum column B if the column A value is equal to or greater than the 1st of the month in C2, and less than the 1st of the next month
looking at column F, the same formula for the year would be:
=SUMIFS(B:B;A:A;">="&DATE(E2,1,1);A:A;"<"&DATE(E2+1,1,1))
Try:
=SUMPRODUCT(--(MONTH($A$2:$A$10)=MONTH(C2));($B$2:$B$10))
But be sure that C is a date column (2012-10-xx). Es 2012-10-01.

Resources