How can I aggregate date data with EntityFramework but without skipping entries with no data? - sql-server

How can I aggregate data by week with EntityFramework but without skipping weeks for which there is no data? So, basically if there is no data for given week - I want to get 0 or NULL as a result for that week.

Agreeing with Luke's comment above, if you know the weeks included in the search, can you just push your results onto a pre-filled week->result Map of some type initialized to zero?
A quick google shows this smarter than me guy likes this answer too:
http://thenullreference.com/blog/analytical-queries-using-entity-framework-over-date-ranges-using-linq/

Related

Comparation Periods in Google Data Studio

I'm creating a in google data studio that has a table behind with data by day.
I need it to be comparable with the month before, but there's a catch that I'm currently stuck!
The period should be something like:
DAY(date)/MONTH(date)-1/YEAR(date)
This allows the comparation between periods with different number of days, example:
Date of analysis: 28/06/2021 - 27/07/2021
Date of comparation: 28/05/2021 - 27/06/2021
When trying to create something like this in DataStudio (with date range controls) none of the options does this, and for what I've explored, there isn't an option to do a formula like the one above.
The closest I get is "Previous Period" but that makes the Date of Comparation 29/05/2021 - 27/06/2021, missing the 28/05/2021.
I'm really stuck and running out of ideas, I've even considered changing the SQL query behind to convert the days somehow.
I've done this by mocking the dates for the comparator.
The other way is to create two series, and don't use the comparator.
Series #1 will have label 28/06/2021 and data from 28/06/2021 (current period).
Series #2 will have label 28/06/2021 (the same) and data from 28/05/2021 (previous period).
They plot nicely:

Google Data Studio apparently bugging year sorting in combined data sources

I have a combined data source that seems to work fine when I sort a bar chart using any metric.
However, as you can notice, the years are not in correct order.
When I select sorting ("Classificar") as year ("Ano") it bugs.
I noticed it is classifying "Ano" in the sorting area as a metric, but as a matter of facts thats a dimension. I didn't manage to find a way to change that.
About the data:
Ano is years in XXXX format
Receita LĂ­quida is Net Revenues in number format
Am I doing something wrong or that's a data studio bug and there is nothing we can do?
Unfortunately, not using combined data sources is not an option in this case (but when I cancel the combined data sources, it works fine and sorts by the year as it should be - still as a metric but it works).
Well, no one answered and I finally found a way to solve it.
Google Data Studio is indeed bugging the year sorting. However it only happens if year is a date object or a number. I fixed it when I turned it into text.

ValueFilter for DateTime Attributes

I'm working with the Blog app and I see how to filter the Blog posts by year using the Visual Query Designer. I use the querystring value that has the year and in the ValueFilter and my properties are as follows:
Attribute: PublicationMoment
Value: [QueryString:year]-01-01 and [QueryString:year]-12-31
Operation: between
How would I get the posts from a specific month and year, if those values are passed via query string parameters. Because the months of the year have a varying number of days, I'm not sure how you would accomplish this in the Value field of the ValueFilter. Currently I'm passing the 2 digit month as the parameter.
I tried something like: [QueryString:year]-[Querystring:month]
Operation: contains
but the above operation doesn't really work because the datatype is a DateTime object.
I could do it in the razor view but I'm afraid that the paging datasource would have too many pages in it since it would be based on the larger subset of posts for the given year that was passed in the querystring parameter.
Is there any way to do this with the filter?
Basically dates are not perfectly handled yet, but there are a few ways to do it using the visual query:
Use the correct date in the query like between [QueryString:Start] and [QueryString:End] and calculate the correct dates there where you generate the links
Since your main problem with the "between" filter is actually that it would include the last day too, you could also use a two filters a >= first date and another < second date, so the first-date would be the year/month and day 1; the second one is year-month and day 1 as well
Last but not least: if you do it with razor and LINQ you shouldn't run into any performance issues - it's technically the same thing the pipeline does and it's been tested to perform well with tens of thousands of records.

What is the optimized way for queries on partial dates in GAE Text Search?

Need to get entities filtering by month instead of complete date values (E.g. Birthdays) using Google App Engine Text Search. On verifying GAE docs, I think it is not possible to query date fields by month directly.
So in order to filter them by month/date, we consider saving each date sub value like Date(DD), Month(MM) and Year(YYYY) as separate NUMBER field along with complete date field.
I verified locally that we can achieve by saving like this. But is this the correct way of saving dates by splitting each field when we want to query on date sub values?
Is there any known/unknown limit on number of fields per document apart from 10GB size limit in GAE Text Search?
Please suggest me.
Thanks,
Naresh
The only time NUMBER or DATE fields make sense is if you need to query on ranges of values. In other cases they are wasteful.
I can't tell from your question exactly what queries you want to run. Are you looking for a (single) specific day of the month (e.g., January 6 -- of any year)? Or just "anything in June (again, without regard to year)"? Or is it a date range: something like January 20 through February 19? Or July 1 through September 30?
If it's a range then NUMBER values may make sense. But if it's just a single specific month, or a single month and day-of-month combination, then you're better off storing month and day as separate ATOM fields.
Anything that looks like a number, but isn't really going to be searched via a numerical range, or done arithmetic on, isn't really a number, and is probably best stored as an ATOM. For example, phone numbers, zip codes (unless you're terribly clever and wanting to do something like "all zip codes in San Francisco look like 941xx" -- but even then if that's what you want to do, you're probably better off just storing the "941" prefix as an ATOM).

How to get last year's same week data in SOLR

How do I get last years same week data?
I used fq=trans_date:[NOW-1YEAR/DAY-7DAY TO NOW-1YEAR/DAY] on date field which will give me last 7 days data for last year. But that approach doesn't take into account calender weeks.
It's probably easier to calculate the boundaries for your week number last year in the frontend and then query Solr with the date interval. That way you can get the behavior you want regarding sundays/mondays as well.
Solr does not provide a nice way to do this.
It would be really cool if you could do fq=trans_date:[NOW-1YEAR/WEEK TO NOW-1YEAR/WEEK] but this is not supported.
Nevertheless, you could create a quick function using php or javascript using each language's native Date operators and get the Week number from today to produce start and end points to feed solr in a query like [1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z].

Resources