I have a datatable whose structure is as under
Week Dates Key_Factors Factor_Values
--- ----- ----------- -------------
1 29/12/2000 Factor_1 19.20
1 29/12/2000 Factor_2 20.67
1 29/12/2000 Factor_3 10
2 21/12/2007 Factor_1 20.54
2 21/12/2007 Factor_4 21.70
I have a Object model like
WeekNumber(int)
Dates(Datetime)
FactorDictionary (Dictionary<string,double>)
I am trying to populate the data from DataTable to my Object Model whose needed output is as under
Desired Output
----------------
WeekNumber : 1
Dates : 29/12/2000
FactorDictionary:
Key_Factors: Factor_1 Factor_Values:19.20
Key_Factors: Factor_2 Factor_Values:20.67
Key_Factors: Factor_3 Factor_Values:10
WeekNumber : 2
Dates : 21/12/2007
FactorDictionary:
Key_Factors: Factor_1 Factor_Values:20.54
Key_Factors: Factor_4 Factor_Values:21.70
i.e. The result is grouped by weeks.
Can I achieve the same by using LINQ.
I am using C#(3.0) with framework(3.5)
Thanks
I am a bit confused by the way you have worded the question, but yes, you can easily group by weeks from a DateTime field using LINQ. The following group by examples should get you started.
Related
Kdb question:
They're multiple rows in a table and I want to check if all the rows if the column meets a condition.
So the column StartDay = ***
How can I check each single row for that column?
Select from t where StartDay = '$"***"
Just gives me type errors.
Any help would be appreciated !
Assuming the column StartDay is of date type like in the following example
q)show t:([]StartDay:.z.d+til 3;number:til 3;sym:`abc`def`ghi)
StartDay number sym
---------------------
2021.02.19 0 abc
2021.02.20 1 def
2021.02.21 2 ghi
Then the following query will work
q)select from t where StartDay=2021.02.19
StartDay number sym
---------------------
2021.02.19 0 abc
The example you have given seems like you are trying to query a column of symbol type. Here are two examples of that
q)select from t where sym=`$"ghi"
StartDay number sym
---------------------
2021.02.21 2 ghi
q)select from t where sym=`ghi
StartDay number sym
---------------------
2021.02.21 2 ghi
Perhaps the following guide on where in q-sql will help.
id datetime new_column datetime_rankx
1 12.01.2015 18:10:10 12.01.2015 18:10:10 1
2 03.12.2014 14:44:57 03.12.2014 14:44:57 1
2 21.11.2015 11:11:11 03.12.2014 14:44:57 2
3 01.01.2011 12:12:12 01.01.2011 12:12:12 1
3 02.02.2012 13:13:13 01.01.2011 12:12:12 2
3 03.03.2013 14:14:14 01.01.2011 12:12:12 3
I want to make new column, which will have minimum datetime value for each row in group by id.
How could I do it in Power BI desktop using DAX query?
Use this expression:
NewColumn =
CALCULATE(
MIN(
Table[datetime]),
FILTER(Table,Table[id]=EARLIER(Table[id])
)
)
In Power BI using a table with your data it will produce this:
UPDATE: Explanation and EARLIER function usage.
Basically, EARLIER function will give you access to values of different row context.
When you use CALCULATE function it creates a row context of the whole table, theoretically it iterates over every table row. The same happens when you use FILTER function it will iterate on the whole table and evaluate every row against the filter condition.
So far we have two row contexts, the row context created by CALCULATE and the row context created by FILTER. Note FILTER use the EARLIER to get access to the CALCULATE's row context. Having said that, in our case for every row in the outer (CALCULATE's row context) the FILTER returns a set of rows that correspond to the current id in the outer context.
If you have a programming background it could give you some sense. It is similar to a nested loop.
Hope this Python code points the main idea behind this:
outer_context = ['row1','row2','row3','row4']
inner_context = ['row1','row2','row3','row4']
for outer_row in outer_context:
for inner_row in inner_context:
if inner_row == outer_row: #this line is what the FILTER and EARLIER do
#Calculate the min datetime using the filtered rows
...
...
UPDATE 2: Adding a ranking column.
To get the desired rank you can use this expression:
RankColumn =
RANKX(
CALCULATETABLE(Table,ALLEXCEPT(Table,Table[id]))
,Table[datetime]
,Hoja1[datetime]
,1
)
This is the table with the rank column:
Let me know if this helps.
I have a bunch of records in the format of
DATE TYPE
---------- ------
06/21/2014 TYPE A
06/22/2014 TYPE A
06/23/2014 TYPE A
06/24/2014 TYPE B
06/25/2014 TYPE C
06/26/2014 TYPE C
06/27/2014 TYPE A
...
I would like to print out a report that showed the range of type where these parameters existed in sequence.
START END LENGTH
---------- ---------- ------
TYPE A 06/21/2014 06/23/2014 3
TYPE B 06/24/2014 06/24/2014 1
TYPE C 06/25/2014 06/26/2014 2
TYPE A 06/27/2014 06/27/2014 1
Is there any way to display the data in this format from the schema I have been given?
Try the following:
1) Create a group by "type". In the group expert, configure it so that it will not order the result (i think it is called "in original order").
2) Suppress the detail section.
3) In the group footer, show the "type" field, put a summarize of minimum "date" (the start), put a summarize of maximum "date" (the end), put a summarize of count (the length).
my data
column1 column2
1-Sep-11 31-Aug-12
1-May-12 30-Apr-14
1-Mar-09 28-Feb-14
1-Apr-13 31-Mar-14
1-Apr-10 31-Mar-13
i want how many years difference between column1 and column2
out put like
column1 column2
1-Sep-11 31-Aug-12 1
1-May-12 30-Apr-14 2
1-Mar-09 28-Feb-14 5
1-Apr-13 31-Mar-14 1
1-Apr-10 31-Mar-13 3
please let me know
Please try:
=YEAR(B1)-YEAR(A1)
select to_date(Column1,'DD-MON-YYYY')- to_date(Column2,'DD-MON-YYYY') from Table;
Excel solution:
If you only want the difference between the years, i.e. coming from 31-Dec-13 to 1-Jan-14 should result in 1 year, use pnut's formula =YEAR(B1)-YEAR(A1).
If you're interested in the real underlying duration, i.e. 1-Apr-13 to 31-Mar-14 would be 0 years, use this formula: =INT((B1-A1)/365)!
I am building an SSRS 2008 R2 report with a SharePoint list as the dataset (can't use a database...but not sure it would help here anyway).
Here is a sample of the data I have (only relevant fields shown).
Workstream Title Show_On_Workstream_Report Value
---------- ------ ------------------------- ------
W-A T-A True 1
W-A T-B False 2
W-A T-C False 3
W-B T-D True 1
W-B T-E True 2
W-B T-F False 2
W-C T-G False 1
W-C T-H False 2
W-C T-I False 2
I need my tablix output to be the following.
Workstream/Title Max_Value
---------------- ---------
W-A 3
T-A 1
W-B 2
T-D 1
T-E 2
*note that W-C is NOT shown in the tablix output since no entries have Show_On_Workstream_Report set to true.
*This I believe is where the kicker is in this problem...
I got the Tablix format down in regards to grouping and whatnot but can't quite figure out how to both include all records for the workstream in the Max_value calculation but only show the "selected" titles under the workstream.
Items that I believe would need to be filled in.
Row Groups
Workstream
Filters: ?
Title
Filters: Show_On_Workstream_Report = True
I am open to custom report code if you think it would solve the problem.
You have 2 row groups, WorkStream, and its child Title (the details line)?
Add a total before the Title line, set it to pick the max from Workstream group. The workstream group should not have the filter applied
=Max(Fields!VALUE.Value, "Workstream")