How to combine many query in spreadsheet if one or more query is empty - mysql

Problem
I have some data from spreadsheet and want to match with date with query, and combine many query.
Question
My query will work if all col i choose is'nt empty. But my data (col) will not all be filled, some will be left blank. If I try with my query one data blank don't want to appear.
Example
=IFERROR({IFERROR(QUERY(dashboar_data;"SELECT C,I WHERE J = date'" & TEXT(DATEVALUE(B5);"yyyy-mm-dd") & "'";0);dashboar_data/0);
IFERROR(QUERY(dashboar_data;"SELECT C,M WHERE N = date'" & TEXT(DATEVALUE(B5);"yyyy-mm-dd") & "'";0);dashboar_data/0);
IFERROR(QUERY(dashboar_data;"SELECT C,Q WHERE R = date'" & TEXT(DATEVALUE(B5);"yyyy-mm-dd") & "'";0);dashboar_data/0)})
Its will work if 3 col is filled, i want if one col empty other query still work

You may try to fake data with iferror. Produce the same number of columns with empty values:
iferror (... , {""\""})

Related

Triggering a checkbox set based on multiple values in mulitple fields FM Pro 15 Adv

We have a situation whereby we need to establish a clausal function querying data from two fields.
We have an 'Item Purchased' field, and five second hand item fields (SH Item 1, SH Item 2, etc). If either (or both) of these fields contain one of a list of specific products by name, a checkbox is enabled (ticked) which in turn triggers conditional formatting.
We have the checkbox and the formatting in place, but I can't find an eloquent means to make an IF query using Case or PatternCount etc to trigger the checkbox - I'm a little out of my depth!
I've attempted (successfully) to use a simple nest of IF statements to trigger the checkbox
but there must be a better way to trigger a 'true' result over a list of values, rather than copying repeating it i.e (Item Bought="Roland"; "Yes"; (sh item 3="Roland"; "Yes"; etc:
If(Item Bought="Orla"; "Yes"; If(sh item 1="Orla"; "Yes"; If(sh item 2="Orla"; "Yes"; If(sh item 3="Orla"; "Yes"; "No")))
I was hoping to learn of a better way to query the presence of a dozen or so discrete values over several discrete fields.
The quick fix for your issue could be:
Let (
values = List ( Item Bought ; SH Item 1 ; SH Item 2 ; SH Item 3 ; SH Item 4 ; SH Item 5 )
;
not IsEmpty ( FilterValues ( "Orla" ; values ) )
)
This will return a result of 1 (True) if any of the listed fields contains the value "Orla", 0 (False) otherwise - so you can use it directly as the formula for conditional formatting.
However, as I stated in a comment above, this is not a good solution overall.
Sounds like you can easiest use an OR operator between the criteria in your IF or CASE statement to get what you want. Also, check out the Filtervalues function as it looks to be relevant to your need.

VBA Code for Multiple Text Search in one Column from List

Need to search multiple text in Description column from List column (which will be in different Sheet later) if Found the exact Item from List in Description column it will be return in Result column with comma after each item.
Please note that from this code there is a problem - see in Description column below picture, its mentioned "I am testing for SMDB" but in Result Column its showing DB MDB and SMDB. The Result should me SMDB only. Please advice
Function aconcat(a As Variant, Optional sep As String = "") As String
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
As you did not include the matching function code, this answer is a guess.
You have DB, MDB, SMDB, ... as searched values.
The text I am testing for SMDB contains the text SMDB but it also contains MDB (as SMDB contains the text MDB) and DB (as SMDB contains the text DB).
You could split your Description using different separators (whitespace, comma, semi-comma ...) to get an array of words and then try to match these words with your searched values.

SUM values of all entries' cost column matching a list of items

Here's my sheet setup:
I have a sheet "Inventory" that holds rows of all my inventory items in stock. Every item has a value/column for "Cost", and a column for "Sale Price".
I have another sheet "Photography", that will have for every row/entry a cell which specifies which are the list of items used in the photo, referenced by some inventory item ref. And from that I want to vlookup or something, to fetch the "Cost" of all those items in the list, and SUM them up.
That way I can know for a specific photo, what are all the items used in the photo, and how much is the cost of all those items (summed up).
Then I will do the same for the "Sale Price", that way for every photo I take, I'll be able to tell the cost of that product item "as is" (with all the different inventory items), and the sale price.
Example:
I was able to do that for only 1 item, but I want the formula to work on the "list" of items in B9.
I even tried with this query formula, I just didn't know how to say "matching any item from the list", which will be a string in another cell:
=SUM(QUERY(A:B,"select B where A matches 'ID-100'"))
If your "items used" column consistently uses comma-space separated format for item lists, the following will work.
=query(Cost!A:B, "select sum(B) where A = '" & join("' or A = '", split(B9, ", ")) & "' label sum(B) ''")
Here, split splits the list of items used into individual item Ids. These are then joined by putting ' or A = ' in between, for example:
ID-101' or A = 'ID-101
There are bits prepended and appended to form the query string, e.g.,
select sum(B) where A = 'ID-101' or A = 'ID-101' label sum(B) ''
which does the job. The label part is necessary to get one-cell output, without a "Sum(Cost)" header getting in the way.
A detail concerning split: as written above, split(B9, ", ") splits by either comma or space (ignoring empty string in the output). So it will work even with ID-1,ID-2, ID-3 ID-4. On the other hand, this may be a problem if your IDs contain spaces. The stricter splitting mode is split(B9, ", ", False) which requires the whole string ", " to be used as a separator.

Applying a "Sum(Filter(" to a range using ArrayFormula

I'm having an issue making a formula becoming an array. The formula I have as of now is
Cell S3 =
=sum(FILTER('Junkyard 2'!$G$3:$H,'Junkyard 2'!$B$3:$B>=$S$5,'Junkyard 2'!$B$3:$B<=$T$5,
'Junkyard 2'!$C$3:$C=N8
(Junkyard 2 is where all the data gets dumped. S5 and T5 are dates. So basically I'm trying to get a list of numbers that is between 2 dates and that matches the name of the guy (Cell N8) and the adding the total hours. This was a workaround as I could not get the sumifs to work)
I've made it in a way that even if user were to insert another row, the formula would apply to the new row as well by doing this
Cell S3 =
=ARRAYFORMULA(IF(ROW(R7:R)=7,"", sum(FILTER(
'Junkyard 2'!$G$3:$H,'Junkyard 2'!$B$3:$B>=$S$5,'Junkyard 2'!$B$3:$B<=$T$5,
'Junkyard 2'!$C$3:$C=N8
My issue right now is I can't apply this to the whole S3:S.
By changing the last part to
'Junkyard 2'!$C$3:$C=N8:N would not give me the proper answer.
Can anyone help me apply this to a range?
The image below is the "Junkyard 2 Sheet"
What you want to do might be most easily achieved with the QUERY formula (Reference) as you can filter and aggregate in one command with much more flexibility than SUMIFS.
Try adjusting this formula to your needs:
=QUERY('Junkyard 2'!B3:H,
"SELECT SUM(G) + SUM(H)
WHERE B >= date '" & TEXT(U4, "yyyy-mm-dd") & "' AND
B <= date '" & TEXT(U5, "yyyy-mm-dd") & "' AND
C = '" & U6 & "'")

Find result then range and copy

I'm having some trouble trying to make a function that acts like vlookup but returns a range rather than a cell
The data to search through looks like this
Sometimes there is a space separating sometimes not
What I would like to do is to look up 16 from my main page and return all the values in that range.
the code I currently am using will only return the first line in a messagebox
Public Function findrulepos(target) As Range
Dim ruleStart, ruleEnd, ruleEnd2 As String
Dim RuleRange As Range
'Dim ruleEnd As Range
MaxRule = 100000
MaxRow = 100000
Set target = Sheets("main").Range("E2")
Sheets("ResRules").Select
For i = 3 To MaxRow
If CStr(ThisWorkbook.Sheets("ResRules").Range("A" & i).Value) = _
CStr(target.Value) Then
ruleStart = _
ThisWorkbook.Sheets("ResRules").Range("A" & i).Offset(0, 1).Text
Exit For
Else
End If
Next i
End Function
If we can assume that the numeric group labels in col A are sequential, then I think this will achieve what you need:
Enter the numeric label you are wanting to extract (16 in your example) into cell E1
Note that =MATCH(E1,A:A,0) gives us the row number where group 16
starts, which is the first row we want to copy. Similarly,
=MATCH(E1+1,A:A,0) gives us the row number where group 17 starts,
which is one row below the last row we want to copy. (Unfortunately
that's not true for the very last group of code, but to rectify that
you just need to add a dummy number at the very bottom of the data
in col A.)
Enter the formula =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1),"") in F1. That should copy the first value of the selected code block -- [DO] ADD TO QUEUE P in your example.
Copy F1 down as many rows as the largest code block is likely to be.
The one problem with that is that it will put 0 whenever it copies a blank row. So you have to explicitly check for that case, e.g. by changing the formula in F1 to =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),IF(ISBLANK(INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"",INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"")