Filter by Date then Aggregate value isn't working OData - odata

I'm trying to retrieve some data with OData, but when I send this Query : $filter=(General eq '401000' and date(DateComptable) ge 2022-06-01T00:00:00Z and date(DateComptable) le 2022-06-30T00:00:00Z)&$apply=groupby((General),aggregate(Debit with sum as TotalDebit, Credit with sum as TotalCredit)) I'm gettng this error :
Property or path DateComptable isn't available in the current context.
It was removed in earlier transformation.
Any idea on how to solve that problem?

The problem here was that the groupby ALWAYS happens before the filter, so I needed to use $apply=filter(General eq '401000' and date(DateComptable) ge 2022-06-01T00:00:00Z and date(DateComptable) le 2022-06-30T00:00:00Z)/groupby((General),aggregate(Debit with sum as TotalDebit, Credit with sum as TotalCredit)).
Doing so, the filter is trigger before the groupby and it works smoothly

Related

How to receive messages in ascending by received date order in graph api

I am trying to receive email messages via Microsoft Graph API:
requestBuilder
.Delta()
.Request()
.Expand("attachments")
.GetAsync(ChildCancellationToken.Token);
but messages come in descending order by ReceivedDateTime. For example we have 15 new messages with ReceivedDateTime = n, where n represents date time.
In first part will come:
[15,14,13,12,11,10,9,8,7,6 (deltaHash="someValue")]
in second:
[5,4,3,2,1 (deltaHash=NULL)]
So, the oldest email will come the latest (LIFO, not FIFO).
But I expect to get:
[1,2,3,4,5,6,7,8,9,10 (deltaHash="someValue")]
[11,23,13,14,15 (deltaHash=NULL)]
What I tried: I tried OrderBy(string value).
For these two I get exceptions:
.OrderBy("ReceivedDateTime asc")
.OrderBy("ReceivedDateTime")
This is working fine:
.OrderBy("ReceivedDateTime desc")
but this is the same as default behavior and I think this is a bug actually. So there is no way to sort emails in ASC order.
How to solve on first look very simple and common requirement?
Looks like this is a known issue as specified in the documentation.
The only supported $orderby expression is
$orderby=receivedDateTime+desc. If you do not include an $orderby
expression, the return order is not guaranteed.
So for now you need to sort them on your end by writing your own code.
I can confirm that .OrderBy("ReceivedDateTime asc") is now working as of the version of the microsoft-graph API I am using which is 5.36.0

How to filter out empty arrays/lists in OData v4 Query?

In OData V4, you are able to filter out empty strings as follows:
OData/v4/2.0/Case?filter=Date ne null
or OData/v4/2.0/Case?filter=Date ne ''
I, however, have an OData query which requires filtering out an empty array/list of names (empty would be: [] so an empty list). Lists cannot be filtered out in the same way:
OData/v4/2.0/Case?filter=Names ne null
does not work. Same goes for the other method.
Is there another way to filter out lists like this Names one?
Thanks in advance
...Or you can use any() operator.
The any operator without an argument returns true if the collection is not empty.
docs
OData/v4/2.0/Case?$filter=Names/any()
If your service supports this operation, you can use the $it literal:
OData/v4/2.0/Case?filter=$it/Names/$count gt 0
The below one was working for me, hope this helps.
https://api-uk.securitycenter.windows.com/api/machines?$filter=not machineTags/any()
Am filtering out the results where the machine tags are empty array.

Query with difference returns no data

I've a query that uses difference function and I can't understand why it returns no data.
The query is:
SELECT
difference(FIRST(grid_power_counter)) as grid_power_consumed
FROM homesolar.origin.main GROUP BY time(15m)
If I remove the difference function it returns data:
SELECT
FIRST(grid_power_counter) as grid_power_consumed
FROM homesolar.origin.main GROUP BY time(15m)
Also, I can get results if I add a where time > now()-24h to the select with difference function.
I really can't understand that behavior. Can someone help me?
Q: My query would only work if I add the where filter to it. Why is that so?
Quoted from influxdb's Groupby time doc:
Basic GROUP BY time() queries require an InfluxQL function in the
SELECT clause and a time range in the WHERE clause.
I suspect your first DIFFERENCE query didn't work because it was missing the mandatory WHERE filter for the Groupby time(...) function.
The Group by time() clause could be returning no rows and hence not.
This could potentially be a github issue for the influx team as I think their query parser should be complaining to you about the missing where filter for Group by time.
References:
https://docs.influxdata.com/influxdb/v1.5/query_language/data_exploration/#the-group-by-clause

NEO4j 3.0 retrieve data between certain period

I'm using NEO4J 3.0 and it seems that HAS function was removed.
Type of myrelationship is a date and I'm looking to retrieve all relation between two dates such as my property "a" is greater than certain value.
How can I test this using NEO4j
Thank you
[EDITED to add info from comments]
I have tried this:
MATCH p=(n:origin)-[r]->()
WHERE r>'2015-01'
RETURN AVG(r.amount) as totalamout;
I created relationship per date and each one has a property, amount, and I am looking to compute the average amount for certain period. As example, average amount since 2015-04.
To answer the issue raised by your first sentence: in neo4j 3.x, the HAS() function was replaced by EXISTS().
[UPDATE 1]
This version of your query should work:
MATCH p=(n:origin)-[r]->()
WHERE TYPE(r) > '2015-01'
RETURN AVG(r.amount) as totalamout;
However, it is a bad idea to give your relationships different types based on a date. It is better to just use a date property.
[UPDATE 2]
If you changed your data model to add a date property to your relationships (to which I will give the type FOO), then the following query will find the average amount, per p, of all the relationships whose date is after 2015-01 (assuming that all your dates follow the same strict YYYY-MM pattern):
MATCH p=(n:origin)-[r:FOO]->()
WHERE r.date > '2015-01'
RETURN p, AVG(r.amount) as avg_amout;

OData query filter for dateTime range

I have a DateTime property in the data returned by a service that looks like
"SDateTime":"2014-06-29T03:30:00.000".
I need to write a query to get a collection which has the date less than "2014-06-26T03:30:00.000" and greater than "2014-06-23T03:30:00.000"
How to write a filter for the dateTime?
Thanks.
In OData V4 date filtering format has changed, the correct filter will be
$filter=SDateTime gt 2014-06-23T03:30:00.000Z and SDateTime lt 2014-06-26T03:30:00.000Z
For example
http://services.odata.org/V4/OData/OData.svc/Products?%24filter=ReleaseDate%20gt%201995-09-01T00:00:00Z%20and%20ReleaseDate%20lt%201995-12-01T00:00:00Z
For previous versions of OData see previous answer
$filter=SDateTime gt datetime'2014-06-26T03:30:00.000' and SDateTime lt datetime'2014-06-23T03:30:00.000'
It works in this service: http://services.odata.org/V3/OData/OData.svc/Products?$filter=ReleaseDate%20gt%20datetime%271995-09-01T00:00:00%27%20and%20ReleaseDate%20lt%20datetime%271995-12-01T00:00:00%27
Breeze will automatically construct an OData filter under the covers for any query. So to query for a date will look something like this in Breeze.
var query = new EntityQuery("Orders")
.where("orderDate", ">", new Date(1998, 3, 1));

Resources