I am trying to only query data that has a number > 0 in Column K within this complex string.
=QUERY('Form Responses 1'!A1:K,"SELECT *" & if(COUNTBLANK('Helper Formulas'!A1:A3)=3,""," WHERE " & TEXTJOIN(" AND ",TRUE,'Helper Formulas'!A1:A3)),1)
I tried...
=QUERY('Form Responses 1'!A1:K,"SELECT * WHERE K > 0" & if(COUNTBLANK('Helper Formulas'!A1:A3)=3,""," WHERE " & TEXTJOIN(" AND ",TRUE,'Helper Formulas'!A1:A3)),1)
But keep getting an error.
Not sure what I need to do.
try:
=QUERY('Form Responses 1'!A1:K,
"where K > 0"&IF(COUNTBLANK('Helper Formulas'!A1:A3)=3,,
" and "&TEXTJOIN(" and ", 1, 'Helper Formulas'!A1:A3)), 1)
The second formula has two WHEREs. Replace the second one with AND, something like:
=QUERY('Form Responses 1'!A1:K,"SELECT * WHERE K > 0" & if(COUNTBLANK('Helper Formulas'!A1:A3)=3,""," AND " & TEXTJOIN(" AND ",TRUE,'Helper Formulas'!A1:A3)),1)
You may need to tweak this if you end up with too many "AND"s.
When troubleshooting this sort of thing it's often helpful to just display the string in the cell (i.e. just the bit inside the query() function). That would have shown up the error quite quickly.
Related
Hello i am trying to sort a map in flutter and i have encountered several methods but none have helped so far.
{ 11-Mittwoch: 07:20:58-07:21:03-23:44:37-00:00:00, 15-Sonntag: 11:11:02-11:11:32-00:00:29-00:00:00, 10-Dienstag: 07:36:20-07:20:53-23:44:32-00:00:00, 28-Samstag: 15:32:18-15:32:21-00:00:01-00:00:01, 30-Montag: 08:25:50-16:28:57-08:03:06-00:00:00, 1-Sonntag: 20:39:11-20:39:33-00:00:15-00:00:06, 3-Dienstag: 17:30:14-17:30:19-00:00:04-00:00:00, 18-Mittwoch: 07:54:51-17:38:01-09:43:09-00:00:00, 5-Donnerstag: 08:17:11-22:07:50-03:45:09-10:05:28, 17-Dienstag: 07:00M-15:20M-7:00M-1:00M, 9-Montag: 18:10:28-18:10:32-00:00:04-00:00:00, 6-Freitag: 07:36:54-14:56:13-07:19:19-00:00:00, 2-Montag: 08:28:39-15:44:11-04:21:33-01:05:34}
as you can see from the code above the keys are a combination of date and day seperated by (-). the approach that i need is how to order this type of map in an ascending order instead of starting from the eleventh day of the month.
i tried using this code:
var mapEntries = allData.entries.toList()
..sort((a, b) => a.key.replaceAll(" ", "").split("-")[0].compareTo(b.key.replaceAll(" ", "").split("-")[0])),
allData
..clear()
..addEntries(mapEntries),
but this is the output i get:
{ 1-Sonntag: 20:39:11-20:39:33-00:00:15-00:00:06, 10-Dienstag: 07:36:20-07:20:53-23:44:32-00:00:00, 11-Mittwoch: 07:20:58-07:21:03-23:44:37-00:00:00, 15-Sonntag: 11:11:02-11:11:32-00:00:29-00:00:00, 17-Dienstag: 07:00M-15:20M-7:00M-1:00M, 18-Mittwoch: 07:54:51-17:38:01-09:43:09-00:00:00, 2-Montag: 08:28:39-15:44:11-04:21:33-01:05:34, 28-Samstag: 15:32:18-15:32:21-00:00:01-00:00:01, 3-Dienstag: 17:30:14-17:30:19-00:00:04-00:00:00, 30-Montag: 08:25:50-16:28:57-08:03:06-00:00:00, 5-Donnerstag: 08:17:11-22:07:50-03:45:09-10:05:28, 6-Freitag: 07:36:54-14:56:13-07:19:19-00:00:00, 9-Montag: 18:10:28-18:10:32-00:00:04-00:00:00}
it sorts all the ones's, then the two's and so on.
i would appreciate any good advice on what i am doing wrong, thanks in advance
My theory that is that you are comparing string values when you are sorting and not the integer values. Try parsing the values from string to integer first, and then it should work.
sort((a, b) => int.parse(a.key.replaceAll(" ", "").split("-")[0]).compareTo(int.parse(b.key.replaceAll(" ", "").split("-")[0])))
In Power BI Desktop i have a table from an excel file and i want to split a row based on a division between the value of a specific column and a default number.
In more details lets assume tha we have a table like this :
if the default value we want to devide column Amount is 50,then the desirable result would be something like that :
Do you have any idea how can i implement that in Power query editor or with dax?
Thanks
Tested this in Power Query for Excel, but hopefully should work for you in Power BI too. If you create a function like:
divisionToList = (numberToDivide as number, numberToDivideBy as number) as list =>
let
divisionResult = numberToDivide / numberToDivideBy,
isResultValid = (divisionResult >= 0) and (Number.Mod(divisionResult, 1) = 0),
errorIfInvalid = Error.Record("Cannot create a list with " & Text.From(divisionResult) & " items", Number.ToText(numberToDivide) & " / " & Number.ToText(numberToDivideBy) & " = " & Text.From(divisionResult), null),
listOrError = if isResultValid then List.Repeat({divisionResult}, divisionResult) else error errorIfInvalid
in listOrError,
It should divide two numbers and return a list of length d in which each element is d (d is the result of the division). This list can then, in the context of a table, be expanded into new rows.
There is some basic error handling in the function for cases where the division yields a problematic number (since you can't have a list with, for example, 5.1 elements or -1 elements). You can change/remove this handling if necessary.
I think this code below takes me from your first image to your second image -- and hopefully will give you some idea on how to go about achieving this.
let
mockData = Table.FromColumns({{200, 400}, {"A", "B"}}, type table [Amount = number, Description = text]),
defaultValue = 50, // Not sure what logic is required for arriving at this figure, so have simply assigned it.
divisionToList = (numberToDivide as number, numberToDivideBy as number) as list =>
let
divisionResult = numberToDivide / numberToDivideBy,
isResultValid = (divisionResult >= 0) and (Number.Mod(divisionResult, 1) = 0),
errorIfInvalid = Error.Record("Cannot create a list with " & Text.From(divisionResult) & " items", Number.ToText(numberToDivide) & " / " & Number.ToText(numberToDivideBy) & " = " & Text.From(divisionResult), null),
listOrError = if isResultValid then List.Repeat({divisionResult}, divisionResult) else error errorIfInvalid
in listOrError,
invokeFunction = Table.TransformColumns(mockData, {{"Amount", each divisionToList(_, defaultValue), type list}}),
expanded = Table.ExpandListColumn(invokeFunction, "Amount")
in
expanded
I have a query that returns a dynamic number of columns. I need to dynamically add the same amount of custom columns. I have successfully gotten this far. I'm stuck creating the formulas for the custom columns. This is what I have so far. (This is not the actual query, this is simplified)
Here is the Code:
Test = List.Accumulate(MyList, Source,
(state, current) => Table.AddColumn(
state, "A Temp" & Number.ToText(current), each [A1])
)
For now, I just added [A1] as a place holder for the formula. I need the formula to accumulate as follows:
A Temp1 = [A1] / [TOTAL]
A Temp2 = [A2] / [TOTAL]
A Temp3 = [A3] / [TOTAL]
Above is not actual code. Just what I need the formulas to do for each custom column.
Is this possible? I have tried everything I could think of. I'm using power query in excel BTW.
This isn't exactly what you asked for, but I think it will help.
Test = List.Accumulate(
List.Select(Table.ColumnNames(Source), each _ <> "TOTAL"),
Source,
(state, current) => Table.AddColumn(state,
"Temp " & current,
each Record.Field(_, current) / [TOTAL]))
It's not exactly what you asked for as it gives column names like Temp A1 instead of A Temp1.
I know the title is a mouth-full - sorry about that but trying to be specific here.
DB: MySql (technically Maria)
ColdFusion (technically Lucee: 5.x)
The array looks like the following:
NOTE: the outter most array only shows part of 2 and could continue through into the 30's.
I'm looking to perform a loop over the array to insert the elements marked as "string" in the image into the database using one query. Query has been trimmed for the sake of clarity and conciseness:
for (outer = 1; outer <= ArrayLen(myArray); outer++) {
local.currentrow = local.currentrow + 1;
for (inner = 1; inner <= ArrayLen(myArray[outer]); inner++) {
local.sql = "
INSERT INTO table (uuid, typeID, menuId, activityID, userID)
VALUES (
'#local.uuid#',
#myArray[outer][inner][1]#,
#myArray[outer][inner][2]#,
#myArray[outer][inner][3]#,
#arguments.formDataStruct.userID#
)";
queryExecute(local.sql);
}
}
I'm looking for something along this line but as written, it isn't working:
local.sql = "
INSERT INTO table (uuid, typeID, menuId, activityID, userID)
VALUES (
if (local.currentrow gt 1) {
,
}
for (outer = 1; outer <= ArrayLen(myArray); outer++) {
local.currentrow = local.currentrow + 1;
for (inner = 1; inner <= ArrayLen(myArray[outer]); inner++) {
'#local.uuid#',
'#myArray[outer][inner][1]#',
'#myArray[outer][inner][2]#',
'#myArray[outer][inner][3]#',
'#arguments.formDataStruct.userID#'
}
})
";
queryExecute(local.sql);
The error message I'm getting is
Element at position [1] doesn't exist in array
but if I perform a writedump[1][3][3] (e.g.), I'll get the value 24.
I would recommend against looping over an INSERT statement and rather just loop over VALUES to generate a single INSERT statement. A single INSERT will perform significantly faster, plus it will minimize the connections to your database.
Build out the list of values with something like:
for (var outer in arguments.inArray) {
for (var inner in outer) {
// Concat elements of inner array to a SQL VALUE string. If UUID is supposed to be a unique identity for the row, use Maria's uuid() instead of CF (or skip the UUID insert and let Maria do it).
// inArray elements and inUserID should be sanitized.
local.values &= "( uuid(), '" & inner[1] & "','" & inner[2] & "','" & inner[3] & "'," & local.userID & ")," ;
}
}
local.values = left(local.values,len(local.values)-1) ; // Get rid of the last comma.
local.sql = "INSERT INTO table (uuid, typeID, menuId, activityID, userID) VALUES " & local.values ;
After you've built up the SQL INSERT string, execute the query to INSERT the records. (You would probably build the above function differently to handle building the query string and parameters and then executing it all in one place.)
Don't forget to sanitize your array and other inputs. Does the array come from a source you control or is it user input?
https://trycf.com/gist/7ad6af1e84906b601834b0cc5ff5a392/lucee5?theme=monokai
http://dbfiddle.uk/?rdbms=mariadb_10.2&fiddle=d11f45f30723ba910c58a1e3f7a7c30b
I am new to Esper and i am working on Storm-Esper collaboration.Through my main class,i send queries to a bolt which contains esper while the esper-bolt sends the tuple which contain the results to a printer bolt.My problem is that,although the result of a query is correct as for the values,the attribute values are not in the correct order.For example,i have a query which selects attributes from a pilot's table: name,surname,airline and i should have the result in the same order.However i get:name,airline,surname.I have tried everything concerning group by and order by.I suppose it must be an Esper's fault when creating the event's map which contains the attributes-values.I paste the main class code and the esper bolt code where the map is processed.Any idea why is that happening is most welcome!
**mainclass**
.addStatements(("insert into pilotStream " +
"select * " +
"from Log.win:time(120 second) A "))
.addStatements(("insert into employeeStream " +
"select * " +
"from Emp.win:time(120 second) A "))
.addStatements(("insert into CombinedEvent "+
"select tick.pilotName as p_name , " +
"tick.pilotSurname as p_surname , " +
"tick.airline as p_airline " +
"from pilotStream.win:time(120 second) as tick, " +
"employeeStream.win:time(120 second) as rom "+
"where tick.airline = rom.employeeAirline "+
))
**espebolt**
Map<String, Object> emap = (Map<String, Object>) newEvent.getUnderlying();
String Event_name = newEvent.getEventType().getName();
//System.out.println(Event_name);
for (Map.Entry<String, Object> entry : emap.entrySet()) {
// String key = entry.getKey();
String val = String.valueOf(entry.getValue()) ;
//System.out.println(key+" :"+val);
//System.out.println(val);
values.add(val);
}
collector.emit(Event_name, toTuple(newEvent, values, false));
values.removeAll(values);
The result should be : source: Esper-Print:2, stream: CombinedEvent, id: {}, [John, Snow, Lufthansa]
Instead,i get:source: Esper-Print:2, stream: CombinedEvent, id: {}, [John, Lufthansa, Snow]
P.S.The toTuple functions simply gets the values of the attributes through the values list of strings and puts them into a tuple which is emitted to printerbolt.In the espebolt code there is some printing in comments which helped me see that the problem is in the map which esper creates internally.
By default Esper generates Map events. This can be changed into object-array events when setting a configuration or with annotations. Map events use "HashMap" and not "LinkedHashMap". The "HashMap" is not ordered when iterating the key-value pairs but takes much less memory. Object-array is ordered. For ordered access to Map events there is the "EventType" that you can get from a statement which returns you the property names in order.