I need to be able to display data for all date range and for the same date range but only for Saturdays.
Data stored in sql server.
Table:
DateTime Vlaue
Is it possible to create linq to sql query which would do that?
Or just select all for particular range and than on server side find all Saturdays?
What is the better way to do that?
You should be able to do something like this:
var results = Entities.YourTable.Where(r => r.SomeDate.DayOfWeek == DayOfWeek.Saturday);
I'd be inclined to just query the database once, then use linq to objects on the result set for the saturday data...
var values = db.Values.ToList(); // assuming your table is called values
var satValues = values.Where( v => v.TheDate.DayOfWeek == DayOfWeek.Saturday);
Related
I created the list of the dates between two dates (minimum and maximum) from another table where i compare the max date and today.
let
first = List.Min(#"Mizan (Banka&Kasa)"[Tarih]),
last = List.Max(
{(List.Max(#"Mizan (Banka&Kasa)"[Tarih])), Date.From(DateTime.LocalNow())}
),
howmanydays = Number.From(last) - Number.From(first) + 1,
Source = List.Dates(first, howmanydays, #duration(1, 0, 0, 0))
in
Source
But I am sure there must be an easier way to achieve this list.
Any ideas ?
Thats pretty much it, unless you prefer to omit howmanydays and use
Source = {Number.From(first) .. Number.From(last)}
then expand and convert format to date
If you want to create a table with the dates of another table maybe the best is:
CREATE NEW TABLE
date = CALENDAR(maxx(table_name, table_name[Date]),TODAY())
table_name is the table you want to select
table_name[Date] is the cell you want to get the last date
Here is my setup:
I have a date slicer that I created by doing this:
d_date = Calendar(min('Table_1'[CTD]),max('Table_1'[CTD])
Here is what my dax looks like for my variables currently:
var FirstVisibleVDate = Min('d_date'[Date])
var LastVisibleDate = Max('d_date'[Date])
My problem(s):
Problem 1: I am doing a running average, I want the running average to adjust itself based on the dates selected in the slicer. I don't think this is possible, is it?
So basically, something like this:
var FirstVisibleVDate = Min(value set in the date slicer)
var LastVisibleDate = Max(value set in the date slicer)
Date range=
Var MinDate = CALCULATE(MIN(Table1[transaction date]),ALLSELECTED(Table1[transaction date]))
Var MaxDate = CALCULATE(MAX(Table1[transaction date]),ALLSELECTED(Table1[transaction date]))
Source:
https://community.powerbi.com/t5/Desktop/Capture-Time-Slicer-Minimum-Value/m-p/820372
If you are going to make a selection over the slicer then that will limit the rows that are visible in the Matrix visual, you will only see the result for the dates selected, so you will have to create a duplicate disconnected Date table that will not filter the rows of the visual.
I have made a couple of forum post on this topic as well as some videos:
Posts:
https://forum.enterprisedna.co/t/dax-calculation-for-choose-n-specific-date/16408
https://forum.enterprisedna.co/t/learning-resources-about-disconnected-date-tables/15416/2
https://forum.enterprisedna.co/t/cumulative-transactions/11803/19
Videos:
https://www.youtube.com/watch?v=WFJThyfQt-A&ab_channel=AntrikshSharma
https://www.youtube.com/watch?v=fLWfdlAaHlQ&ab_channel=AntrikshSharmaAntrikshSharma
My datasource has a column that contains a comma-separated list of numbers.
I want to create a dataset that takes those numbers and turns them into groupings to use in a bar chart.
requirements
numbers will be between 0-17 inclusive
groupings: 0-2,3-5,6-10,11-17
x-axis labels have to be the groupings
y-axis is the percent of rows that contain that grouping
note that because each row can contribute to multiple columns the percentages can add up to > 100%
any help you can offer would be awesome... i'm very new to BIRT and have been stuck on this for a couple days now
Not sure that I understand the requirements exactly, but your basic question "split dataset column into multiple rows" can be solved either using a scripted dataset or with pure SQL (depending on your DB).
Either way, you will need a second dataset (e.g. your data model is master-detail, and in your layout you will need something like
Table/List "Master bound to master DS
Table/List "Detail" bound to detail DS
The detail DS need the comma-separated result column from the master DS as an input parameter of type "String".
Doing this with a scripted dataset is quite easy IFF you understand Javascript AND you understand how scripted datasets work: Create a report variable "myValues" of type object with a default value of null and a second report variable "myValuesIndex" of type integer with a default value of 0.
(Note: this is all untested!)
Create the dataset "detail" as a scripted DS, with one input parameter "csv" of type String and one output parameter "value" of type String.
In the open event of the scripted DS, code:
vars["myValues"] = this.getInputParameterValue("csv").split(",");
vars["myValuesIndex"] = 0;
In the fetch event, code:
var i = vars["myValuesIndex"];
var len = vars["myValues"].length;
if (i < len) {
row["value"] = vars["myValues"][i];
vars["myValuesIndex"] = i+1;
return true;
} else {
return false;
}
For example, for the master DS result row with csv = "1,2,3-4,foo", the detail DS will result in 4 rows with
value = "1"
value = "2"
value = "3-4"
value = "foo"
Using an Oracle DB, this can be done without Javascript. The detail DS (with the same input parameter as above) would then look like:
select t.value as value from table(split(?)) t
For the definition of the split function, see RedFilter's answer on
Is there a function to split a string in PL/SQL?
If you get ORA-22813, you should change the original definition
create or replace type split_tbl as table of varchar2(32767);
to
create or replace type split_tbl as table of varchar2(4000);
as mentioned on https://community.oracle.com/thread/2288603?tstart=0
It's also possible with pure SQL in 11g using regexp_substr (see the same page).
create parameters in the scripted data set. we have to pass or link actual dataset values to scripted dataset parameters through DataSet parameter Binding after assigning the scripted data set to Table.
I have a table in Mongo. One of the fields is a DateTime. I would like to be able to get all of the records that are only for a single day (i.e. 9/3/2011).
If I do something like this:
var list = (from c in col
where c.PublishDate == DateTime.Now
select c).ToList();
Then it doesn't work because it is using the time in the comparison. Normally I would just compare the ToShortDateString() but NoRM does not allow me to use this.
Thoughts?
David
The best way to handle this is normally to calculate the start datetime and end datetime for the date in question and then query for values in that range.
var start = DateTime.Now.Date;
var end = start.AddDays(1);
...
But you'd also be well advised to switch to the official C# driver now. You should also use UTC datetimes in your database (but that gets more complicated).
I have a table with many anniversaries : Date + Name.
I want to display the next anniversary and the one after with Linq.
How can i build the query ?
I use EF
Thanks
John
Just order by date and then use the .Take(n) functionality
Example with a list of some objects assuming you want to order by Date then Name:
List<Anniversaries> annivDates = GetAnnivDates();
List<Anniversaries> recentAnniv = annivDates.OrderBy(d => d.Date).ThenBy(d => d.Name).Take(2).ToList();
If the anniversaries are stored in regular DateTime structs, they may have the 'wrong' year set (i.e. wedding or birth year). I suggest writing a function which calculates the next date for an anniversary (based on the current day) like:
static DateTime CalcNext(DateTime anniversary) {
DateTime newDate = new DateTime(DateTime.Now.Year, anniversary.Month, anniversary.Day);
if (newDate < DateTime.Now.Date)
newDate = newDate.AddYear(1);
return newDate;
}
Then you proceed with sorting the dates and taking the first two values like described in the other postings:
(from e in anniversaries orderby CalcNext(e.Date) select e).Take(2)