How to use previous row value for vertically merged cells in google sheets while fetching using pygsheets? - pygsheets

I am trying to get the data in the merged cell Level 1 in all the smallest rows, or iterate over the rows created by the merged cells.
I am getting
[['Level 1', 'Level 2', 'Level 3'], ['', '', 'Level 3'], ['', '', 'Level 3']]
when I am fetching the data for the first 3 rows using get_all_values method.
The expectation is to get:
[['Level 1', 'Level 2', 'Level 3'], ['Level 1', 'Level 2', 'Level 3'], ['Level 1', 'Level 2', 'Level 3']]
instead.
Currently I am using dictionaries to hold the data using a lot of logic to figure out the missing column data. Is there a better way of flattening the merged cells to their respective rows?

Assuming your data begin at row #2, you can complete the column A by, in D2
=ArrayFormula(if($C2:$C="",,lookup(row(A2:A),row(A2:A)/if(A2:A<>"",1,0),A2:A)))
and to complete column B, in E2
=ArrayFormula(if($C2:$C="",,lookup(row(B2:B),row(B2:B)/if(B2:B<>"",1,0),B2:B)))
and in F2
=ArrayFormula(if($C2:$C="",,C2:C))
in this way you will get a complete set of data

Related

Counting true/false values form measure 'A', in measure 'B' on matrix visual

I have a riport, in which I need to make a measure, which counts the 'true' values of another measure.
My partner's sales prices are calculated with a measure, which is then put into a matrix visual.
Column 'A' contains the partner name (as there are several) Column 'B' is the item name, 'C' is their sales price and 'D' is the price they should sell the product for.
Example_1 matrix visual with open hierarchy:
What I need, is a measure, that I can put into the matrix, which then calculates those items, that are not sold for the given price, so when I close the table hieararchy and I only see the partner's name, I should have the info of how many products they sell for lower than given sales price (making it easier to rank them)
What I'm having trouble with, is to count the 'true' values of a measure, with another measure.
It's important, that I cannot make a new colmn into the source tables. I must have a measure, which counts 'True' values of another, as their sales prices are also calculated.
Example_2 matrix visual with closed hieararchy with the needed result value:
The first two items from Example_1 were sold for a lower than given price. My first measure will determine this by doing a true/false logical test.
My second measure which gives back two, should calculate the 'true' values of the first measure.
Practically the measures should look like this:
Measure_1 = if([measure_salesprice] < sum('given_pricelist'[Price] , "Lower" , "Not lower")
--> this one works perfectly
Measure_2 = Calculate(DISTINCTCOUNTX('Sales table', 'Sales table[Item name]),[measure_lowerpricetruorfalse] = "Lower")
--> now, this doesn't
Is this possible somehow?
I've tried several DAX combinatains like:
Calculate --> DISTINCTCOUNT, COUNTROWS, COUNTA, COUNTAX, COUNTX( with filter)
Always the same true/false error.
Please be informed that There is no function in DAX called DISTINCTCOUNTX ----> It is DISTINCTCOUNT only as of 2 Nov 2022:
Regarding your question: Use this DAX Code As Measure:
You don't need to categorize them as Lower or not Lower if you don't need this info to use later.
YourMeasure =
VAR GroupLower = FILTER(
'Sales table', [Partner sales price] < [Given sales price])
RETURN
COUNTX(
GroupLower,[Item name])
If you try to test it on a matrix visual:

SQLite: Using COALESCE inside a CASE statement

I have two tables: one with record of a person with initial number, and a second one with records of changes to this number.
During a join, I do coalesce(latest_of_series, initial) to get a singular number per person. So good so far.
I also group this numbers into a groups, on order these groups separately. I know I can do:
select
coalesce(latest, initial) as final,
case
when coalesce(latest, inital) > 1 and coalesce(latest, inital) < 100 then 'group 1'
-- other cases
end as group
-- rest of the query
but that's of course horribly unreadable.
I tried:
select
coalesce(latest_of_series, initial_if_no_series) as value,
case
when value > 1 and value < 100 then 'group 1'
-- rest of the cases
end as group
-- rest of the query
but then the sqlite complains that there's no column "value"
Is there really no way of using previous result of coalesce as a "variable"?
That's not an SQLite limitation. That's an SQL limitation.
All the column names are decided as one. You can't define a column in line 2 of your query and then refer to it in line 3 of your query. All columns derive from the tables you select, each on their own, they can't "see" each other.
But you can use nested queries.
select
value,
case
when value >= 1 and value < 100 then 'group 1'
when value >= 100 and value < 200 then 'group 2'
else 'group 3'
end value_group
from
(
select
coalesce(latest_of_series, initial_if_no_series) as value
from
my_table
group by
user_id
) v
This way, the columns of the inner query can be decided as one, and the columns of the outer query can be decided as one. It might ever be faster, depending on the circumnstances.

SSRS created 2 conditional counts and get same result for both

I have a very simple SSRS report - a census of employees with health insurance. I need a count of how many have single policies and how many have family policies. I created a conditional COUNT statement using the two parameters. However, they both produce the TOTAL number of policies instead of only the parameter they are supposed to be filtering on.
Expressions I used:
=COUNT(IIF(Fields!Deduction.Value = "Single", Fields!Deduction.Value,0))
=Count(IIF(Fields!Deduction.Value = "Family", Fields!Deduction.Value,0))
I have 79 rows. 54 rows say "Single" and 25 rows say "Family". The output shows 79 for BOTH groups.
The "Single" and "Family" designation is based on a case statement that converts multiple kinds of policies into the 2 basic values of Single and Family.
Any ideas on why this is happening?
You are doing a COUNT of results.
0 is a result that counts as 1 the same as any other number.
Use NOTHING instead of 0. COUNTs do not include NULL (NOTHING) values.
=COUNT(IIF(Fields!Deduction.Value = "Single", Fields!Deduction.Value, NOTHING))
The other way would be to assign a 1 for a match, 0 for non-match and then SUM the results.
=SUM(IIF(Fields!Deduction.Value = "Single", 1, 0))

Oracle: Composite unique key with Date column

I have created a table with composite unique key as below--
create table test11
(
aa number,
bb varchar2(10),
cc DATE,
dd number,
ee NUMBER
);
CREATE UNIQUE INDEX TEST11_IDX ON TEST11 (AA,BB,CC);
Now, whenever I try to insert data, I get this error:
ORA-00001: unique constraint (CDUREFDB.TEST11_IDX) violated
INSERT INTO TEST11 VALUES (1, 'AA', SYSDATE, 1, 1);
commit;
INSERT INTO TEST11 VALUES (1, 'AA', SYSDATE, 1, 1);
commit;
Is that because of DATE column is considering Date value till seconds?
Because I could see below query is returning is result--
select to_char(CC,'DD-Mon-YY HH:Mi:SS AM') from test11;
TO_CHAR(CC,'DD-MON-YYHH:MI:SSAM')
---------------------------------
17-Mar-16 04:28:37 PM
17-Mar-16 04:28:43 PM
So, what can be done in order to only consider Date value (not hours, mins, secs precision) as unique key member.
Also, DATE column above(CC) has partition on it.
UPDATE::
In this table, we have RANGE partition on DATE column(CC).
And we are planning to remove partitions periodically (i.e. after some days interval).
So if I Don't use direct CC in unique index ( instead of making trunc as Justin suggested) then i am getting error as ORA-01502: index 'CDUREFDB.TEST111_IDX' or partition of such index is in unusable state if I try to insert data after some old partition got removed .
UPDATE_1
As per #Justin suggestion below, this issue is resolved creating virtual column like below:
CREATE TABLE TEST11
(
AA NUMBER,
BB VARCHAR2(10),
CC DATE,
DD NUMBER ,
EE NUMBER,
FF DATE generated always AS (TRUNC(CC)) virtual
)
PARTITION BY RANGE
(
FF
)
INTERVAL
(
NUMTODSINTERVAL(1,'DAY')
)
(
PARTITION partition_test_1 VALUES LESS THAN (TO_DATE('01-APR-2006','dd-MON-yyyy'))
);
CREATE UNIQUE INDEX TEST111_IDX ON TEST11 (AA,BB,FF) LOCAL; -- creating unique local index
A date always has a time component so your two rows have different cc values. You could create a function-based index based on the trunc(cc) value which will set the time component to midnight.
CREATE UNIQUE INDEX TEST11_IDX
ON TEST11 (AA,BB,trunc(CC));
Of course, that means that if you want a query to use the index, you'd want to ensure that your predicate is on trunc(cc) rather than cc.

Grads plotting data from different files (different points of time) in one 2D (height – time) plot

I downloaded data from the american gfs weather modell (from ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2014101812/master, edit date if you read more than 1 month later). Those are grib-files.
I am using grads to plot data and it works fine if I plot data from 1 timestep (=1 file) on a map.
So my first try was to open the first 2 files and to make a shaded plot showing areas with the same wind speed in the same color. What I get is an empty plot with correct axes.
'open gfs.t12z.mastergrb2f00.ctl'
'open gfs.t12z.mastergrb2f03.ctl'
'set dfile 1'
'set time 12Z17OCT2014'
'set gxout shaded'
'set lat 50'
'set lon 0'
'set lev 1000 200'
'set t 1 2'
'd sqrt(ugrdprs*ugrdprs+vgrdprs*vgrdprs)*1.9438'
'set dfile 2'
'set time 15Z17OCT2014'
'set t 1 2'
'd sqrt(ugrdprs*ugrdprs+vgrdprs*vgrdprs)*1.9438'
I am using opengrads – Grid Analysis and Display System (GrADS) Version 2.0.2.oga.2.
Anyone who can help me plotting data from different timesteps (= different files) into one plot?
You can use one .ctl file to plot multiple data files.
I have done this with .gdat files, so I guess you will be able to do it with GRIB.
You should make new .ctl file using grads templates.
http://www.iges.org/grads/gadoc/templates.html
Basically, in dset line you will put a file name similar to
dset gfs.t12z.mastergrb2f%h2.grb
where %h2 represents 2 digit hour.

Resources