I've read multiple answers to a similar query, but none seem to hit the spot.
Imagine I have a table that contains 10 rows, how do I retrieve 3 random rows from this table using Entity Framework? Not just 1 random row, but 3 random rows - each being different from the other?
Thanks in advance
var threeRandomFoos = foos.OrderBy(x => Guid.NewGuid()).Take(3);
Instead, there is a simpler way,
var threeRandomFoos = foos.OrderBy( x=> SqlFunctions.Rand()).Take(3);
Guid.NewGuid will be little slower in performance, why not use Random specified by SqlFunctions itself?
Related
I have this google sheets input.
Players
Loot
Player1
4
Player2
1
Player3
4
Player4
2
What I'm seeking to do is to simplify this formula.
=AND(B2>=3,B3>=3,B4>=3,B5>=3)
This is what i did so far. as suggested by #Harun24hr in this comment.
=ArrayFormula(COUNTIF(B2:B5>=3,"TRUE"))=COUNTA(B2:B5)
Can this formula be simplified further and still get TRUE in a single cell when all of Loot values is >= 3?
It's hard to understand exactly what you mean by simpler, but this formula is dynamic which I would consider simpler....?
=Count(filter(B2:B,B2:B>=3))=Count(B2:B)
Also, I try to avoid using CountTf after #ScottCraner mercilessly taught me the in the comments sections of one of my less impressive answers from a few years ago by saying:
COuNTIF is a calc hog. Fill column A with the row number out to 100,000 rows and then add the formula: =OR(COUNTIF(A:A,A1)) and fill down the same number of rows. Depending on your machine this may take a while. =ISNUMBER(MATCH(A1,A:A,0)) is much quicker.
My computer pretty much melted (though that was an Excel Discussion while this is Google sheets?).
Select the entire range B2:B5 and check if it's greater than or equal to 3 using >=. >= operator supports arrays. AND merges the values.
=ARRAYFORMULA(AND(B2:B5>=3))
try:
=SUMPRODUCT(B2:B>=3)=COUNTA(B2:B)
I want to import central banks interest rates into google sheets. The table I'm using can be found here:
=importhtml("https://www.investing.com/central-banks","table",1)
For each items that I want from this table, I would have a function like (in this example, to fetch 1.00%):
=value(substitute(index(importhtml("https://www.investing.com/central-banks","table",1),2,3),",",""))
If I need this whole table, which consists of 12 rows (excluding header) x 4 columns, I would have 48 such formulas. It seems to me that:
this is messy, and
making 48 calls to the investing.com URL where one could probably suffice.
So I decided to try a different approach. In another tab of my google sheets, I call the whole table:
In my other tab, I thought to query this table (assume it is in a tab called rates) instead. But I don't know how. Is there a way, and if so, what is the correct way to query say:
the first name in the table (Federal Reserve (FED))?
the fourth interest rate in the table (-0.75%)?
Any help is greatly appreciated.
To get 1%, try
=index(importhtml("https://www.investing.com/central-banks","table",1),2,3)
index
adapt parameters to fetch
the first name in the table (Federal Reserve (FED)) =index(importhtml("https://www.investing.com/central-banks","table",1),2,2)
or the fourth interest rate in the table (-0.75%) =index(importhtml("https://www.investing.com/central-banks","table",1),5,3)
To get all % per banks at once
=query(importhtml("https://www.investing.com/central-banks","table",1),"select Col2,Col3",1)
The answer he gave you Mike Steelson is good, but if I were you, I would make it in such a way that I could change the parameters at any time
=query(importhtml("https://www.investing.com/central-banks","table",1);"select Col2 WHERE (Col3='"&$A1&"')",1)
where A1 = 1.00% or any number entered into that cell
I want to merge TWO columns of data (join or concatenate). The issue I'm running into is that I need it to return an empty cell. If either one of the cells or let's say the 2nd column does not have any data it should return nothing.
Here is an image
I have used both concatenate & join text functions. I have looked online for a solution as well but didn't stumble upon what I was looking for. I am fairly new to google spreadsheet so any help will be appreciated.
use in row 1:
=INDEX(IF((A:A="")+(B:B="");;A:A&" "&B:B))
Stumbled upon a strange behavior. This formula:
=ARRAYFORMULA(ROW($A$1:$E$5))
Returns a 5 element column with the row numbers from 1 to 5. I thought that ARRAYFORMULA would iterate through every cell in the range specified and execute the ROW() on it - resulting in a new range of the same size (5 columns, 5 rows), but with the row numbers in cells.
For example =ARRAYFORMULA(ISBLANK($A$1:$E$5)) returns a 5 on 5 range.
I found a way to force the desired behavior (see the answer below), but is there a better way? Am I missing something?
not rly much to say here just that ROW and COLUMN are only one dimensional. in other words, ROW will work only with one single column and COLUMN will work only with one single row - no matter that you feed it with range A1:Z or A1:A
as mentioned you can use MattKing's SEQUENCE to generate the matrix
or shorter:
=ARRAYFORMULA(ROW(A1:A5)*COLUMN(A:E)^0)
or shorter:
=INDEX(ROW(A1:A5)*COLUMN(A:E)^0)
or shorter:
=INDEX(ROW(A1:A5)*{1,1,1,1,1})
I think a lot of people use:
=ARRAYFORMULA(IF(COLUMN(A1:E5),ROW(A1:E5)))
There are a lot of ways to do it, but almost all will involve using two refs.
This is about as small as I could get it. Depends on what your inputs look like as to whether this would make sense to use.
=ARRAYFORMULA(SEQUENCE(1,5,0,0)+SEQUENCE(5))
Here is a workaround for you, man:
=ARRAYFORMULA(ROW($A$1:$E$5) + 0 * ISBLANK(A1:E5))
0 * ISBLANK(A1:E5) part is there just to force the desired behavior without modifying (see that multiplication by 0?) the values you need.
I have two database dumps in Google sheets. They contain several thousand entries - many are identical, but not all. I now need to find all of those where a number in a specific column has increased by a certain number. The problem is that the rows not necessarily are the same, as entries in the database can have been deleted - and more been added, so rows do not add up.
I have tried various forms of 'if' and 'query' - none that have brought me closer to a solution.
I'm thinking that I first need to compare the column where the unique id is to ensure that it is the right entry that is being compared.
I would like to completely automate this, but a semi-manual way of doing this could also be okay.
One solution for this could be to get Google to check the unique id's of the two tabs - and then display the content of a second column in the first tab only where the id's can be found in both tabs.
I just cannot get Sheets to do this.
Any help would be appreciated
if I understood you right you can use filters for your task. For example
=FILTER(YourSheet1!B$2:B;YourSheet2!A$2:A=C2;YourSheet2!D$2:D=E2)
It will return you the line, where A$2:A == C2 and D$2:D == E2 from sheet two. So you can using filters choose data that has equal column values. If there exist copies it will return an error to the cell
Found the solution... A simple LOOKUP was what I needed:
=LOOKUP(B147,stats23Dec!B:B,stats23Dec!G:G)