I have a date table which I use as a slicer. I want date1 to get the minimum date from that range. I then use that date to calculate the number of new user from KPI_summary table andIi want this to be a fixed unchanging value which is returned as newUsers.
However when I plot this with dates the values change. am I missing something? pls see codes below
NewUsers =
var date1 = MIN('Date Table'[Date]) -- get the first date from the slicer
var newUsers = calculate(sum(KPI_SUMMARY[NEW_USERS]), KPI_SUMMARY[JOIN_DATE] = date1) --get the new users from the first date
return
newUsers -- I want to always return the newUsers from the first date of the slicer. it shouldnt change
Try something like this:
NewUsers =
-- get the first date from the slicer
var _date1 =
CALCULATE(
MIN('Date Table'[Date]),
ALLSELECTED('Date Table')
)
var _newUsers =
calculate(
sum(KPI_SUMMARY[NEW_USERS]),
KPI_SUMMARY[JOIN_DATE] = _date1
) --get the new users from the first date
return
_newUsers -- i want to always return the newUsers from the first date of the slicer. it shouldnt change
I used ALLSELECTED() function inside CALCULATE() function to change _date1 variable calculation context.
Also, as you can see, I would advice you to name your variables with "_" prefix. It's much easier to recognize them then.
Related
I need to write a query in SSAS Tabular model where I have a table with a column AREA with some 17 values. I need to write a query where I check if all the values of the AREA column are selected then it should consider the value as "WORLDWIDE". How to do this in if condition? What are the ways to achieve this?
Try with this:
NumOfSelected =
var __TotalItem = countrows(DISTINCT(ALL(Sheet1[ID])))
var __currentSelected = countrows(VALUES(Sheet1[ID]))
return
IF(__TotalItem = __currentSelected, "WorldWidth", "CurrentChoice:" & CONVERT( __currentSelected, STRING))
I have events (from an Event model) that have a starts_at: value in the form of a datetime. e.g.:
2016-02-18 11:00:00:00000
What I want to be able to do is check whether an event is starting this week.
I want to be able to make a list of events that are occuring this week (starting from the latest Monday).
#events = #calendar.events.where( ... )
I thought something along the lines of this:
start_week = Date.today.beginning_of_week(:monday).day()
end_week = Date.today.beginning_of_week(:monday).day()+6
range = start_week..end_week
#events = #calendar.events.where(starts_at: in range)
But it doesn't take into account the month or year. Also I'm not sure how to write the 'where' clause. How should I go about doing this? Thanks
Try this:
start_week = Date.today.beginning_of_week(:monday)
end_week = Date.today.beginning_of_week(:monday)+6
range = start_week..end_week
#events = #calendar.events.where(starts_at: range)
Assuming you want all the events from the current week, something like this should work:
#events = #calendar.events.where(starts_at: Time.zone.today.all_week)
all_week returns a Date range covering the current week.
I an using kendodate picker in my solution.I want to retrieve the dates for full week whenever user selects some date from the kendodatepicker.e.g.lets say today is Feb 21,2014(Friday) whenever user selects some day say Feb 24,2014(Monday) then i need to retrieve its week's dates(starting and ending date).the answer should be(Feb 22,2014-Feb 28,2014)considering the fact that my week starts from Saturday(Feb 22)and ends on Friday(Feb 28).Kindly guide.i am new very much new to kendoUI.thanks
Define the change event handler as:
change : function (e) {
// Get a reference to the row (week) containing the selected date
var tr = $(".k-state-selected", cal._table).closest("tr");
// Get the first day
var first = $("td:first", tr).text();
// Get the last day
var last = $("td:last", tr).text());
}
Example here : http://jsfiddle.net/OnaBai/W9VFB/9/
If you want to have the first and last date as text, then you might use:
var first = $("td:first", tr).find("a").attr("title");
var last = $("td:last", tr).find("a").attr("title");
Example here : http://jsfiddle.net/OnaBai/W9VFB/12/
I’m trying to retrieve dates from the database then use it to compare with current date. How can I get the last date from a list of dates in the database then compare it with the current date? Here’s what I’ve tried but I get a exception: “LINQ to Entities does not recognize the method 'System.DateTime Last…”
var manageDate= from d in db.Enrollments.Select(da=>da.Date) select d;
var manageAssgnDate = from asgn in db.Enrollments.Select(asgn => asgn.Date) select asgn;
List<DateTime> newDate = manageDate.ToList();
I normally use lambdas:
// This gets the max date in the table
var manageDate = db.Enrollments.Max(da => da.Date);
Is this what you were asking for ?
Found a work-around:
var stdAssgn= from sa in db.Assignments where sa.StudentId==currentId select sa.Date;
var dt = stdAssgn.ToList().Last ();
String a = dt.ToString();
and to convert to DateTime if needed...
DateTime b=Convert.ToDateTime(a);
How to show reminder by month?
I have created this partial code and I am stucked how to manipulate to check and get reminder by month.
reminders = ScheduledActionService.GetActions<Reminder>();
if (reminders.Count<Reminder>() > 0)
{
}
else
{
}
If there is reminder I want to check the month and get the month i want.
try this one:
var month = 5; // your month
var remindersOfMonth = ScheduledActionService.GetActions<ScheduledAction>()
.Where(a=> a.BeginTime.Month == month);
According to this when you use GetActions() it will return you a list of
ScheduledAction. Now according to this ScheduledAction has a property called BeginTime which is of type DateTime so it has Month property which is your interest.
variable "a" in the statement is in fact each of ScheduledAction in the collection which are begin evaluated again the month.