Question concerning sorting numbers by string/dealing with tiebreakers? - sorting

I am currently re-educating myself on Google sheets and I was wondering if there was a way to sort a set of numbers by string to deal with tiebreakers (i.e. a win/loss/tie record)
Using the SORT function, I was able to sort things correctly based on wins, but I want to be able to adjust it even further. Currently I have something like this...
3-0-0
1-4-0
1-3-0
1-2-0
1-1-0
when I want to have something like this, where the values with the lowest loss record goes on top instead...
3-0-0
1-1-0
1-2-0
1-3-0
1-4-0
Is there another function or a workaround possible to achieve something like this?

=SORT(A1:A5,INDEX(SPLIT(A1:A5,"-"),,1),0,INDEX(SPLIT(A1:A5,"-"),,2),1)
SPLIT(A1:A5,"-") by -
INDEX(SPLIT(A1:A5,"-"),,1) get first column of the split array
INDEX(SPLIT(A1:A5,"-"),,2) get second column
=SORT(A1:A5,col1,0,col2,1) Sort A1:A5 in descending order based on column1 and ascending order based on column 2

While in "human language" something like 3-0-0 could be called "a set of numbers" in "spreadsheet language" it's a text value.
To be able to use the built-in sorting functions in Google Sheets, you should split the values into columns, and guess what, there is a built-in function for that:
Select the column
Click on Data > Split text to columns
Select custom separarator and set -
There are a more options, like using a formulas and scripts.
Sample formula
=ArrayFormula(QUERY(
{A1:A5,REGEXEXTRACT(A1:A5,"-(\d{1,})-")},
"select Col1 order by Col2",0)
)
The above formula use a regular expression to extract the numbers between -, then use QUERY to sorth the values in A1:A5 in ascending order by using these values.

Related

How do I sort the data received from the user, from large to small in SAP ABAP?

I get a variable number of data from the user with the parameter. I want to sort (descending ascending) them among themselves. I tried using order by, but I don't know how to solve it.
My data is separated as follows:
SPLIT sayilar AT '-' INTO TABLE it_char.
I tried these. I guess I can't find what I want. Below is the block of code I tried to sort. I'm doing something wrong, but I don't know what happened.
SORT it_char DESCENDING.
LOOP AT it_char INTO wa_char.
WRITE :/ wa_char.
ENDLOOP.
skip 2.
SORT it_char ASCENDING.
LOOP AT it_char INTO wa_char.
WRITE :/ wa_char.
ENDLOOP.
I set the variable type to c but it doesn't work correctly in double digit numbers.
my parameters screen:
my report screen:
In order to sort an internal table, use the SORT keyword.
To sort a table of strings or type C alphabetically, use:
SORT it_char ASCENDING AS TEXT.
When the line type of the table is numerical and you want to sort from large to small:
SORT it_char DESCENDING.
More information can also be found in this help article.

Returning the last value from the FILTER function in google sheets

I'm using Google Sheets and would like to get the last value in column when it is filtered based on the values in a separate column as shown in the screenshot:
I'd like to get the last value from column A, where the value in column B matches that specified in cell D1.
I've managed to do this with the following:
=INDEX(FILTER($A:$A,$B,$B=$D$1),COUNTA(FILTER($A:$A,$B:$B-$D$1)),1)
This works but it seems unnecessary to have the second FILTER and COUNTA as it makes it harder to understand. Is there no way I can just return the last value from the FILTER function?
Since posting this I've found another way that's more concise, but I have to confess I don't actually understand how it works:
=ArrayFormula(LOOKUP(2,1/($B:$B=$D$1),$A:$A))
Here you will know about sort and array_Constrain:
=array_constrain(filter(sort({A1:A,row(A1:A)},2,false),B1:B=D1),1,1)
or you can use query:
=query(filter({A1:A,row(A1:A)},B1:B=D1),"Select Col1 order by Col2 desc limit 1")
or you can use indirect:
=indirect("A" & max(filter(row(A:A),B:B=D1)))
I know this is a way that I do that sometimes. it takes advantage of the VLOOKUP(....TRUE) [default] option.
=VLOOKUP(9^99,FILTER({ROW(A:A),A:A},B:B=D1),2)

spotfire crosstable sorting

I have a very typical requirement to sort columns in the cross table. I have col1,col2,col3 columns. when col2=col3 it should display first
.
Please let me know whether it can be achieved in Spotfire directly or through scripting.
I do not know of any straight forward way of defining a sort order like this, but in the past I have padded column values with a leading space so they come first when sorted.
Something like this should work
<[COL1] NEST [COL2] NEST CASE WHEN [COL2]=[COL3] THEN Concatenate(" ",[COL3]) ELSE [COL3] END AS [COL3]>

How to filter entries that are not duplicates of entries from others columns in Google Sheets?

I have a column called "Masterlist" which contains values from Lists 1, 2 and 3. It also contains values which are present only in Masterlist.
How can I filter them, like shown at the attached image in Google Sheets?
EDIT: The lists will have more than one entries.
Solution 1
In E2, type in
=filter(A2:A,arrayformula(iserror(match(A2:A,B2:D2,0))))
Check the documentation of filter or match for how to use them. With match, be sure to include the third argument. That is an easy one to forget. arrayformula iterates a formula over a range. The output can be a range, in which case it will print over any un-written cells. When arrayformula interacts with match, it only iterates over the first argument, which is why this solution works.
EDIT: If you have a two-dimensional range to match to, you need to collapse them into a one-dimensional range using the concatenation operators such as
=filter(A2:A,arrayformula(iserror(match(A2:A,{B2:B4;C2:C4;D2:C4},0))))
You can experiment with endings without row indices and let Google Sheets select an ending index for you.
Solution 2
Use the native Filter View feature. Good for the scenarios where you don't need to separately print a list of the unique values in "masterlist".
Go to Data -> Create Filter View
Use the relevant help pages to navigate yourself. I can see a few ways to implement what you desire, including
filter by value on the same column (selecting the actual values manually);
filter by value on a "helper column" where you include a formula in the cells to check whether the content in "masterlist" belongs to the list you want to check against. You can use the match and iserror combo here;
custom formula using a similar formula as above.
If your column A, ie. the "masterlist", is something a user would add to, then Data Validation can be used to good effect in conjunction with Filter View.

Distinct count a field that has been sorted by territory from another source

I am trying to find a way to get a distinct count on a field that is being filtered by a territory without using grouping because of the fact that I need to then pass this value over to another report. The easiest way would be something like this:
distinctcount({Comm_Link.CmLi_Comm_CompanyId}) if {Company.Comp_Territory}='Atlanta'
But for obvious reasons that won't work. Any thoughts?
what you have to do is a running total. Right click on {Comm_Link.CmLi_Comm_CompanyId} insert running total, type of summary will be distinct count and on evaluate where says Use a formula type your condition {Company.Comp_Territory}="Atlanta"
your formula and approach is wrong.. I doubt whether your formula compiled with out any errors...
first create the value and then find the distinct count
if {Company.Comp_Territory}='Atlanta'
Then {Comm_Link.CmLi_Comm_CompanyId}
Now in footer write or you can get it by right click on the filed.
distinctcount({Comm_Link.CmLi_Comm_CompanyId})

Resources