How to filter dates based on its time in Loopback 4? - loopbackjs

I want to find out all the dates which have time more than 10.30 am.
let whereBuilder = new WhereBuilder();
whereBuilder.gt('sessionStartedOn', '10:30:00');
Obviously, this doesn't work. Are there any wildcard characters I should be adding?
The query in PostgreSQL would be something like this -
SELECT * FROM table WHERE date_part('hour', sessionStartedOn) >= 10 AND date_part('minutes', sessionStartedOn) > 30;

I think the second parameter should be of the same type as the value contained by the variable named by the first parameter. In your case I presume it is date. For example: "2022-01-18T00:00:00.000Z"
https://loopback.io/doc/en/lb4/apidocs.filter.wherebuilder.lte.html
PS. If you want to filter for values greater than the value passed as a parameter you should use .gt (>) or .gte (>=) methods.

Related

Calculated column based on What-if parameter

I have a table visual in PowerBI that summarizes work hours by employee. The first column shows the employee name.
When training managers on how to use it I want to anonymize by showing employee numbers instead of names.
I tried adding a what-if parameter Anonymous with values 0 and 1 and use IF() in the DAX of a calculated column but it is not working. It ignores the parameter value.
Person = IF(Anonym[Anonym value] = 0; Time[Name]; Time[Empno])
will always show Name.
Person = IF(Anonym[Anonym value] = 1; Time[Name]; Time[Empno])
will always show Empno.
Another option if you really need to use a column and needs it to be "dynamic" is to use a PowerQuery parameter and add a new column based on it and then create your conditional. The downside of this is that you will have to refresh your query everytime you want to change the parameter

Checking if any value in Column is equal to Todays Date

I'm working in Google Sheets and I am trying to determine if any value of dates listed in the column is equal to Today's Date.
I have tried using the COUNTIF formula the ISDATE formula and the IF formula against the value of TODAY() and nothing seems to be working right.
=IF('Invoices-Quickbooks-Data'!L:L,ISDATE(TODAY()),true)
This formula actually works the best for me. I would expect it to calculate if any of the values equal Today's Date. Ironically this tells me that the answer is TRUE even when none of the dates actually match Today's date so I am not sure what is going on.
First, the reason why your formula is always returning true is because ISDATE(TODAY()) will always return true (when is today not a date?) and furthermore, you can't use an IF statement like that to query a whole column. The first argument to IF is a condition, and a column range is not a condition.
To apply a function over a range, you want to use an ARRAYFORMULA. Here is how you would check a range of cells to see if any value in the column (or range) contains a date equal to today:
=IFERROR(VLOOKUP(TRUE,ARRAYFORMULA(IFERROR(DATEVALUE(A:A)=TODAY(),FALSE)),1,FALSE),FALSE)
Just replace A:A with the range you want to check. The return of an ArrayFormula is an array, which is why I have to use VLOOKUP to check for any TRUE values inside it.
Advanced solution:
A really cool feature in sheets is the query() function, which essentially lets you run a SQL-like query over a range of cells. I like it because it makes formulaes very readable - for example, the entire ARRAYFORMULA solution above can be replaced with:
=IFERROR(QUERY('Invoices-Quickbooks-Data'!L:L,"select count(L) where dateDiff(L,now()) = 0 label count(L) ''",-1) > 0,FALSE)
you can check it with just simple IF formula:
=ARRAYFORMULA(IF(LEN(A2:A), IF(A2:A=TODAY(), TRUE), ))
=ARRAYFORMULA(IF(A2:A=TODAY(), TRUE, ))

Google Data Studio Calculated Field by Extracting String from Event Label Values

I'm trying to use the CASE statement to output string values for an Event Label field using RegEx to produce a table that shows the number of events for each field value. So, if I'm looking for foobar, and other string values separately, within values for Event Label; it may either stand alone or be part of a URL like so:
|[object HTMLLabelElement] | Foobar |
/images/foobar-26.svg
It seems REGEXP_EXTRACT might suit this the best:
CASE WHEN REGEXP_EXTRACT(Event Label, '.(?i)foobar.') THEN Foobar
However, the table produced using the calculated field as the dimension only contains a blank row that seems to be the sum of the number of events.
What am I missing?
I think you need to use REGEXP_MATCH not REGEXP_EXTRACT, given your existing syntax, or to change the syntax to a straight REGEXP_EXTRACT without the CASE element.

Power BI remove duplicates based on max value

I have 2 column; ID CODE, value
Remove duplicates function will remove the examples with the higher value and leave the lower one. Is there any way to remove the lower ones? The result I expected was like this.
I've tried Buffer Table function before but it doesn't work. Seems like Buffer Table just works with date-related data (newest-latest).
You could use SUMMARIZE which can be used similar to a SQL query that takes a MIN value for a column, grouped by some other column.
In the example below, MIN([value]) is taken, given a new column name "MinValue", which is grouped by IDCode. This should return the min value for each IDCode.
NewCalculatedTable =
SUMMARIZE(yourTablename, yourTablename[IDCode], "MinValue", MIN(yourTablename[value]) )
Alternatively, if you want the higher values just replace the MIN function with MAX.

How to search multiple strings in a string?

I want to check in a powerquery new column if a string like "This is a test string" contains any of the strings list items {"dog","string","bark"}.
I already tried Text.PositionOfAny("This is a test string",{"dog","string","bark"}), but the function only accepts single-character values
Expression.Error: The value isn't a single-character string.
Any solution for this?
This is a case where you'll want to combine a few M library functions together.
You'll want to use Text.Contains many times against a list, which is a good case for List.Transform. List.AnyTrue will tell you if any string matched.
List.AnyTrue(List.Transform({"dog","string","bark"}, (substring) => Text.Contains("This is a test string", substring)))
If you wished that there was a Text.ContainsAny function, you can write it!
let
Text.ContainsAny = (string as text, list as list) as logical =>
List.AnyTrue(List.Transform(list, (substring) => Text.Contains(string, substring))),
Invoked = Text.ContainsAny("This is a test string", {"dog","string","bark"})
in
Invoked
Another simple solution is this:
List.ContainsAny(Text.SplitAny("This is a test string", " "), {"dog","string","bark"})
It transforms the text into a list because there we find a function that does what you need.
If it's a specific (static) list of matches, you'll want to add a custom column with an if then else statement in PQ. Then use a filter on that column to keep or remove the columns. AFAIK PQ doesn't support regex so Alexey's solution won't work.
If you need the lookup to be dynamic, it gets more complicated... but doable you essentially need to
have an ID column for the original row.
duplicate the query so you have two queries, then in the newly created query
split the text field into separate columns, usually by space
unpivot the newly created columns.
get the list of intended names
use list.generate method to generate a list that shows 1 if there's a match and 0 if there isn't.
sum the values of the list
if sum > 0 then mark that row as a match, usually I use the value 1 in a new column. Then you can filter the table to keep only rows with value 1 in the new column. Then group this table on ID - this is the list of ID that contain the match. Now use the merge feature to merge in the first table ensuring you keep only rows that match the IDs. That should get you to where you want to be.
Thanks for giving me the lead. In my own case I needed to ensure two items exist in a string hence I replaced formula as:
List.AllTrue(List.Transform({"/","2017"},(substring) => Text.Contains("4/6/2017 13",substring)))
it returned true perfectly.
You can use regex here with logical OR - | expression :
/dog|string|bark/.test("This is a test string") // retruns true