Google Sheets Query with Cell References Only Returning Headers - sql

=query('Budget Data'!$A:$Y, "SELECT A,B, E, w Where A = '"&K1&"'AND W = "&$D$1,-1)
My Query Is looking to retrieve 4 columns from a larger dataset on "Budget Data" sheet dependent on brand name and reporting month date. I am referencing two cells for Brand Name (K1) and Date(D1). However, it is only returning the Header Row of Data. I have double checked data types and everything is matched correctly.
How can I get the rest of the data to show in this query?

Well if you are trying to date match b/w D1 and column W, then try:
=query('Budget Data'!A:Y, "SELECT A,B,E,W Where E = '"&K1&"' AND W=date '"&text(G1,"yyyy-mm-dd")&"'")
if its to match month of the date in D1 cell and relevant month data in column W, then use:
=query('Budget Data'!A:Y, "SELECT A,B,E,W Where E = '"&K1&"' AND month(W)="&month(G1)-1)

Related

I have a conflict Matrix, and a list of users with different access, I want to check whether the user as a conflicting access or not

Conflict Matrix: C = conflict, A = accessible, X = same
Conflict Matrix is as below image
Using the above table as an example, if I wanted to find the access for A & B I would look down the first column for A, and across the first row for B.
The intersection of these two letters would return C for Conflict.
If your data table is in cells A1:I9 and your key lookup is in cells K1:L3 (i.e K1 contains C, L1 is Conflict) you can use a combination of VLOOKUP, INDEX and MATCH.
MATCH("A",$A$1:$A$9,0) will return the row number that A appears in on column A.
MATCH("B",$A$1:$I$1,0) will return the column number that B appears in on row 1.
INDEX($A$1:$I$9, RowNum, ColumnNum) will return the value at the intersection of RowNum & ColumnNum
VLOOKUP(ReturnedValue,$K$1:$L$3,2,FALSE) will return the looked up value of C, A or X.
Stick the four formula together to get your final result (change "A" & "B" to the access values you're looking for:
=VLOOKUP(INDEX($A$1:$I$9,MATCH("A",$A$1:$A$9,0),MATCH("B",$A$1:$I$1,0)),$K$1:$L$3,2,FALSE)
Further reading:
MATCH
INDEX
VLOOKUP

VBA code to sum total of like account numbers

I have a code that matches 2 columns A VS C for like account numbers. If numbers match than it finds if the amounts in Column B & D match. If it does it pastes the lines of data to another spreadsheet.
I am coding a statement to find the like account numbers in column A VS C, but if the amounts don't match in column B & D than it needs to find the like account numbers in column A and sum there amounts to see if it matches the amount in column B.
How would I write the code to collect the sum of the same account numbers in column A?
If Acct = MatchAcct Then
If Amount <> MatchAmount Then
If Acct = nonmatchacct Then
(sum the values in column B for the matched account #s in column A)
The code above says if the Acct (Column A account #'s) = MatchAcct (Column C account #'s) then if Amount (Column B value) doesn't equal MatchAmount (Column D value) then the code sees if Acct (Column A account #'s) equals nonmatchacct (any other account # in Column A). If the account # matches then I want it to sum those amounts in column B.

Count IF multiple criteria/data types match

I'm looking to generate a report to list the number of Cities/Towns that don't meet a certain criteria so on Sheet 2 I have an alphabetical list of all the cities/towns.
I want to do a look up/count if function to state if A2(Sheet 2) can be found anywhere in Column D on Sheet 1 then count it if the date in column L (sheet 1) matches the date in Cell $E$1 (sheet 2) and Column A in Sheet 1 is greater than zero.
I originally done this formula but it is returning an error.
=COUNTIFS(PickData!D:D,Sheet1!A2,PickData!L:L,Sheet1!$E$1,PickData!A:A,PickData!A:A>0)
Is there any other formulas that I'm currently not thinking of? Or is it possible to do this via VBA and it returns the value in to column B either True if it matches or False if it doesn't?
Thanks
Al
The problem with your previous formula is in the final criteria. Update to:
=COUNTIFS(PickData!D:D,Sheet1!A2,PickData!L:L,Sheet1!E2,PickData!A:A,">0")

VBA macro to select cell based on row and column criteria

I'm trying to create a macro that runs with a custom user form shown below. My ultimate goal is to have the Expenditure Category radial select the sheet in the file, then have the PO Number field search column A of the selected sheet to find a match, then subsequently have the Week Ending Date field search row 7 to find a match for the date entered. Where these two intersect (i.e. CN72) is where I want to input what is put in Accrual Amount. I have no idea about how to go about doing this, so any help would be great!
It is a loop inside another loop...I might use something like this..
x = 1
z = 1
datexx = [input]
POnumber = [input]
do
do
if Sheets("[name]").Range("[column]" & z) = Sheets("[name]").Range("[column]" & x) then
'do your stuff here
end if
z = z +1
loop until isempty(Sheets("[name]").Range("[A column that is never empty for all data]" & z)
x = x+ 1
loop until isempty(Sheets("[name]").Range("[A column that is never empty for all data]" & x)

Excel VBA Code to transpose multiple columns into multiple rows

Can somebody please help, i'm a newbie in VBA, i would like to thank you in advance for your help. If there are any links where my question has already been adressed please point me in the right direction. I have searched here and on other sites but i couldn't find anything that atleast get me started. I would like to create VBA code that loops through cells in every row and transpose them into seperate rows as illustrated below.
I have an excel spreadsheet with 12000 rows of data and multiple columns. For each row i have columns "A" to "Q" as static fields. Name, DOB, ID_Number, e.t.c. From columns "Q" to "DD", i have repeated data on "City" and "RegDate" columns, for example: City1, RegDate1, City2, RegDate2, City3, RegDate3,..& CityN, RegDateN. The City names are used as Headers and the data cells show "R" under every city where a person is registered and the registration date in the column next to it, otherwise there is no entry.
I would like to transform this data so that for every City where a person is registered, i will have a new row of data showing the static fields "A" to "P", "City", and "RegDate" i.e. after column "P" i will only have two columns "City" and "RegDate".
I'm really struggling with creating code that loops from Column Q to Column DD creating a new row when ever an "R" is encountered copying rows Columns "A" to "P" and inserting the Name of the City in the new column "Q" and the RegDate in the new Column "R", before moving on to the next row until all the 12000 rows have been transformed.
Any help to get me started would be greatly appreciated especially on setting up the looping that creates a new role for every record with an "R" encountered.
Have you considered just putting this information in two new columns to the far right (DE and DF)? Then you could either hide Q to DD, or delete those columns.
As for the looping code to do this:
Dim cr As Long 'current row
Dim cc As Long 'current column
For cr = 2 To 12000
For cc = 17 To 108 Step 2
If Cells(cr, cc).Value = "R" Then
'make column 109 (DE) in current row = city name
Cells(cr, 109).Value = Cells(1, cc).Value
'make column 110 (DF) in current row = date of registration
Cells(cr, 110).Value = Cells(cr, cc + 1).Value
End If
Next
Next