adds leading zero to a column value Etext template - bi-publisher

How to format the column so that it adds leading zero to a column value.
for example , in the etext template i want to add this logic. using which function can i do this ?
that is if job_code is 2900 then it should come as 002900. I tried adding "0000000" under the format column, but it didnt work.

You could format the column in Data Model sql so it comes to the template already formated..
Select LPAD(COLUMN_NAME, 6, '0') as ALIAS...
Here is an example of LPAD function: ERROR: Function SUBSTR requires a character expression as argument 1. and adding zeroes in front of data

Related

How do I get the column letter of a single row where a particular value equals a test value?

I need to get the letter of the column that has a value in a given row that matches a given value in Google Sheets, assuming that no values in the row are duplicates.
For example, in the above screenshot, if the row is the first row, and the test value is Jun, the formula will return H.
Kind of meta. Appreciate any help.
Answer
The following formula should produce the behaviour you desire:
=REGEXREPLACE(ADDRESS(1,MATCH("Jun",A1:1),4),"[1-9]*",)
Explanation
The =MATCH formula returns the position of the item in a range which has a specified value. In this case, the specified value is "Jun" and the range is A1:1.
=ADDRESS returns the A1 notation of a row and column specified by its number. In this case, the row is 1 and the column is whichever number is returned by the =MATCH. The 4 is there so that =ADDRESS returns H1 instead of $H$1 (absolute reference is its default).
=REGEXREPLACE looks through a string for a specified pattern and replaces that portion of the string with another string. In this case, the pattern to search for is any number. The last argument of =REGEXREPLACE is blank so it simply removes all numbers from the string.
What is left is the letter of the column where the value is found.
Functions Used:
=MATCH
=ADDRESS
=REGEXREPLACE
Now that Google Sheets has added Named Functions, there is an easier way to do this.
To use named functions, go to Data -> Σ Named Functions. A sidebar will pop up. At the bottom use "Add new function" to create a new named function.
I created two functions to do this:
First, COL_CHAR which will take a column reference and return its letter
Second, ALPHA_CHAR which takes a numeric input and converts it to letters. I made this one recursive, so if it's an n-letter column name, it will keep calling itself until it gets the full name.
COL_CHAR just converts the referenced column to a column number and passes that to ALPHA_CHAR. It's formula is:
=ALPHA_CHAR( column(cell) )
where cell is an Argument placeholder. Make sure to add that to the argument placeholder list in the sidebar.
Here is the (recursive) formula for ALPHA_CHAR:
=IF( num > 26, ALPHA_CHAR( INT( num / 26 ) ), "") & CHAR( CODE("A") - 1 + MOD( num, 26 ) )
where num is an Argument placeholder.
By making this recursive, even if Google Sheets expands to allow 4-letter (or more) columns in the future, it will keep iterating through every letter regardless of how many there is.
Then, to get the letter of a column in the spreadsheet, you just call COL_CHAR and pass the cell in the column you want, for example:
= COL_CHAR(BK1)
Will return the string "BK"

Last value of a column in Google Sheets

I was trying to use the following function;
=INDEX(D:D,COUNTA(D:D),1),
in order to get the last currency value of a column, but it returns #ERROR!.
The value im trying to extract
As I montly update this spreadsheet, it would make it very convenient if would etract the last value in the column, e.g. the value marked in the image.
Is there a way (in Google Sheets) to find the last non-empty cell in this column, such that when I update the spreadsheet with a new "last value" it would return that value?
The index(counta()) pattern will fail when the data is sparse, i.e., when there are blank values in the column.
The index(match()) pattern will fail when the data contains a value that is not a number.
To find the last non-blank value in column D, regardless of data type, use the +sort(row()) pattern:
=+sort(D1:D; not(isblank(D1:D)) * row(D1:D); false)
The formula uses semicolons as argument separators to make it work in any locale.
If the column has only currency (ie number) values then you can use something like:
=INDEX(D1:D, MATCH(999^99, D1:D))
or try:
=SORTN(D:D; 1;;ROW(D:D)*(D:D<>""); )

How to print different values to column based on value in another column and other conditions met?

I have a spreadsheet with several columns and I want to return a different value based on the value in Column A and if any of the other columns show a true or 1.
For example
If column A has the value "A" and any column B-N is either TRUE or 1 then I want to return "Good" to column O
If column A has the value "B" and any column B-N is either TRUE or 1 then I want to return "Best" to column O
Link to spreadsheet: https://docs.google.com/spreadsheets/d/12k9usKsOgrOUhtW5WBvfY7WB5hbfnTMSPgXtrqcRFjM/edit?usp=sharing
Try this in cell O2 (where your sample sheets only has values of TRUE, FALSE, Y or N in B2:N):
=arrayformula((trim(transpose(query(transpose(iferror(regexreplace(regexreplace(text(B2:N,),"(FALSE)|(N)",),"(Y)|(TRUE)",if(A2:A="A","Good",if(A2:A="B","Best",))),)),,columns(B2:N))))))
Alternative where values in B:N are either 0 or 1:
=arrayformula((trim(transpose(query(transpose(iferror(substitute(substitute(B2:N,0,),1,ifs(A2:A="A","Good",A2:A="B","Best")),)),,columns(B2:N))))))
B2:N is the range of cells to process.
The inner SUBSTITUTE clears all 0 values.
The outer SUBSTITUTE swaps 1 values for a test to see if values in A contain "A" or "B".
IFS does the test and returns either "Good" or "Best".
IFERROR hides any #N/A values down the sheet where the rows are empty.
TRANSPOSE transposes the data for QUERY.
QUERY is used to collapse empty cells (vertically). columns(B2:N) is used in the header part of QUERY. This is a quirk of QUERY, where the header number >= the columns of data, QUERY does the collapse.
TRANSPOSE reverts the dataset to the previous orientation.
TRIM removes leading or trailing space.
ARRAYFORMULA allows the formula to automatically cascade down the sheet, rather than you needing to drag the formula down (like with =IF(AND({B2:N2}>0, A2="A"),"Good", "")).
So, you already have this partial solution. To get a second condition to be met before printing something to your cell, just add an AND() with a new COUNTIF(), comparing A column with A, and then at the else argument, repeat your original IF(), just changing A for B and the output for each case. I will look like this:
=IF(AND(countif(A2;"A");OR(countif(A2:N2;"Y");countif(A2:N2;TRUE)));"Good";
IF(AND(countif(A2;"B");OR(countif(A2:N2;"Y");countif(A2:N2;TRUE)));"Best";"BAD"))
To use it on every row, just autofill the column O. The row numbers will change accordingly and work on its own.
If you need a new if() statement for a third or fourth case, just repeat it, nesting one IF() inside the other, leaving room for a default error message at the end.

Google Sheets: How do I create an array from a range, adding a column with a constant literal value in every row?

I want to make an array with several columns. The second and subsequent columns are specified as a range pulled from another sheet. The first column is a static constant, that is, every cell in the first column should have the very same literal string value, say 'foo'. I can't find the correct syntax. I'd have thought something like this would work:
={"foo", 'Other Sheet'!C2:F}
but I get "Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 1. Actual: 999." Clearly "foo" needs to be "expanded" to a column with lots of rows. How do I do it, and where are tricks like this documented?
Maybe the answer to this question would give a start: How do I create an array containing a single column, every cell containing "foo", with the number of columns specified by a different range?
Here is an editable sheet illustrating the problem and the desired solution:
https://docs.google.com/spreadsheets/d/17myzKVFN3SDQuubWNdP-dFAbdvdlRbZFkjRpLi2Fas8/edit?usp=sharing
The exact question is this: what formula can I put in cell B9 of Sheet1 to get the current appearance of Sheet1? Notice that I don't know in advance how many rows there are in 'Other Sheet'. It's OK to assume that all rows of Other Sheet have a nonblank value in column C.
You can loop with an arrayformula and assign them to the first column, ending the array with the same size:
={ARRAYFORMULA(if(len('Other Sheet'!C2:C),"foo",)),'Other Sheet'!C2:F}
Side note: that between the {}, if you put a comma ({expr1 , expr2}), the value will be side by side, and if you put a semicolon ({expr1 ; expr2}), the values will be one above the other.
You can use QUERY for that:
=QUERY('Other Sheet'!C2:F, "select 'foo',C,D,E,F where C is not null")
If you want to remove the 'foo' column header, you can use:
=QUERY('Other Sheet'!C2:F, "select 'foo',C,D,E,F where C is not null label 'foo' ''")

format rows in google sheets based on conditional range

I have a data set with 77 rows. One of the columns (let's call it C) contains a name value. I would like to highlight the row if the name in column C is found in a list of names in another column.
Currently, I'm able to check only a single value, instead of a list of values. In conditional format rules, I'm able to enter the following formula
=$C:$C=$GU$1
This, of course, only checks the value against the first name in column GU. I tried to add :$GU$100 to the condition, but that won't work as the condition is now checking if the entry is the same as the entire value from GU1:GU100.
I thought I might try to use a FIND() method to see if the substring were in the larger string. To do that, I attempted the following:
=$C:$C=IF(ISNUMBER(FIND($C$1,$GU$1:$GU$100)),1,0)
While this did not return an error, it also did not highlight any rows. I'm unsure how to format one row based on whether or not the value in that row is an entry in a list elsewhere. Any ideas?
Please select your 'entire row' range (here assumed ColumnsA:G) and Format, Conditional formatting..., Format cells if..., Custom formula is:
=match($C1,$H:$H,0)
choose your Formatting style and Done. Where ColumnH is assumed to have your list.
You can add conditional formatting like this with the custom function option and applying to column C, pretending that the list with names your matching against is in column J:
=IF(ISTEXT(VLOOKUP(C1:C,J:J,1,false)),TRUE,FALSE)

Resources