I want to do a Dax funtion to filter a data based on DateTime values but with a precision of 15 minutes.
How could i do that ?
FILTER(MarketSales;(CompanyX[Date] < (MarketSales[Date] - 15) || CompanyX[Date] > (MarketSales[Date] - 15))
How could i precise 15 minutes and not 15 days ? Or is there any other way to do that ?
Thanks in advance !
you can do the following:
FILTER(MarketSales;(CompanyX[Date] < (MarketSales[Date] - TIME(0,15,0)) || CompanyX[Date] > (MarketSales[Date] - TIME(0,15,0)))
I copied your DAX formula but I think that you should check the first argument of your formula. I think you should use a '+' instead of '-'. But that is only my guess.
Hope it helps you.
Related
One of my first posts, so I'll do my best. I've tried searching this, which is how I got this far..but I could use some help converting some time data in the form mm:ss.000 (that's milliseconds at the end) to seconds with a fraction at the end. For example, 2:15.45 should come out to 135.45.
This works:
t <- "02:15.45" (as.numeric(as.POSIXct(strptime(t, format = "%M:%OS"))) - as.numeric(as.POSIXct(strptime("0", format = "%S"))))
But this one, where I'm trying to use a column of my dataframe (originally in character form) does not work:
starttimesFPsnapjumps <- FPsnapjumps$start (as.numeric(as.POSIXct(strptime(starttimesFPsnapjumps, format = "%M:%OS"))) - as.numeric(as.POSIXct(strptime("0", format = "%S"))))
Perhaps it's because my numbers in the column have an extra 0 - they are mm:ss.000. Any thoughts? Thanks in advance.
I'm quite newbie using MDX, I use it in Power BI in order to create different reports.
I'm actually stuck with an issue after a lot of research in different pages, related to Time Ranges.
In the Cube there is a dimension [Time].[Date].[Date], that goes from 2014 to 2020, so I figure out after many hours that all the options using Current Member wouldn't work.
I need to capture a Measure in the last 7, 30, 60, 90 days.
I found two options:
OPTION 1. Using WITH and Member:
`WITH MEMBER [Measures].x AS SUM
({[Time].[Date].&[20190216]:[Time].[Date].&[20190222])
},[Measures].[Avg Loaned])
SELECT NON EMPTY {[Measures].x} on 0
,NON EMPTY ([Time].[Date].[Date]) on 1
FROM [MYCUBE]
WHERE (Some Conditions...)`
OPTION 2. Using WITH, Range and Member
`WITH
SET [Range] AS
{[Time].[Date].&[20190216]:[Time].[Date].&[20190222]}
MEMBER [Measures].x AS SUM
({nonempty([Range]*[Measures].[Avg Loaned])})
SELECT NON EMPTY {[Measures].x} on 0
,NON EMPTY ([Time].[Date].[Date]) on 1
FROM [MYCUBE]
WHERE (Some Conditions...)`
In both cases I get the correct results, and it seems to keep working if I replace
**[Time].[Date].&[20190222]** --> StrToMember("[Time].[Date].&[" + Format(Now(), "YYYYMMDD") + "]")
But it doesn't work when I replace the first date
**[Time].[Date].&[20190216]** --> StrToMember('[Time].[Date].&[' + Format(dateadd('d',-7,Now()), 'YYYYMMDD') + "]")
OR
**[Time].[Date].&[20190216]** --> StrToMember('[Time].[Date].&[' + Format(dateadd('d',-7,cdate(Now())), 'YYYYMMDD') + "]")
OR
**[Time].[Date].&[20190216]** --> StrToMember('[Time].[Date].&[' + Format(cstr(dateadd('d',-7,Now())), 'YYYYMMDD') + "]")
I'm not sure what's the best way to accomplish the task, OPTION 1 or 2, but the main roadblock is how I'm writting down the starting limit for the range trying to use dateadd.
Thanks in advance, I know that there are many posts about this, I tried to adapt the examples to my code but I failed and after some days I'm not sure what could be the issue.
Rgds
Pablo
In your working example you have StrToMember(" and in non-working example you have StrToMember(', so probably you should use double quotes and not single quotes: StrToMember("[Time].[Date].&["...
I am a beginner in LINQ.I want to perform some conditional operation lik follows,
(from emp in Employees
let DOB=emp.BirthDate.GetValueOrDefault()
let year=DOB.Year
let month=DOB.Month
let EmpAgeInYearsToday=DateTime.Now.Year-year
let EmpAgeInMonthToday=DateTime.Now.Month-month
let temp_year=(EmpAgeInYearsToday-1)
let ExactNoOfMonths_temp=EmpAgeInMonthToday<0?temp_year:EmpAgeInMonthToday
let ExactNoOfMonths=EmpAgeInMonthToday<0?EmpAgeInMonthToday+12&temp_year:EmpAgeInMonthToday
select new{emp.EmployeeID,DOB,
EmployeeAgeToday=EmpAgeInYearsToday+" Years "+ExactNoOfMonths+" Months ").Dump();
Here,
let ExactNoOfMonths=EmpAgeInMonthToday<0?EmpAgeInMonthToday+12&temp_year:EmpAgeInMonthToday
This part is not working. The expression in the left side of & alone is getting executed.I want to perform both the operations. How to achieve this?How to perform multiple operations when the condition is satisfied?
Is there any Other alternate way for doing this?
I think what you mean is something like this:
ExactNoOfMonths = EmpAgeInMonthToday < 0 ?
EmpAgeInMonthToday + 12 :
temp_year ?
EmpAgeInMonthToday :
somethingElse
but there should be a third value (somethingElse) for when EmpAgeInMonthToday >= 0 and temp_year = false.
Edit
What you want is actually pretty complicated. You better just fetch the dates of birth in memory and do the calculation in plain C#.
This CodeProject link gives a possible approach. As you'll see you can't avoid leap years and month lengths: the difference between Feb 28 and Mar 28 is 1 month in a normal year, 1 month and 1 day in a leap year.
How do I count the number of days between these two dates?
start_date = Date.parse "2012-03-02 14:46:21 +0100"
end_date = Date.parse "2012-04-02 14:46:21 +0200"
With the Date (and DateTime) classes you can do (end_date - start_date).to_i to get the number of days difference.
Assuming that end_date and start_date are both of class ActiveSupport::TimeWithZone in Rails, then you can use:
(end_date.to_date - start_date.to_date).to_i
Rails has some built in helpers that might solve this for you. One thing to keep in mind is that this is part of the Actionview Helpers, so they wont be available directly from the console.
Try this
<% start_time = "2012-03-02 14:46:21 +0100" %>
<% end_time = "2012-04-02 14:46:21 +0200" %>
<%= distance_of_time_in_words(start_time, end_time) %>
"about 1 month"
I kept getting results in seconds, so this worked for me:
(Time.now - self.created_at) / 86400
to get the number of days in a time range (just a count of all days)
(start_date..end_date).count
(start_date..end_date).to_a.size
#=> 32
to get the number of days between 2 dates
(start_date...end_date).count
(start_date...end_date).to_a.size
#=> 31
None of the previous answers (to this date) gives the correct difference in days between two dates.
The one that comes closest is by thatdankent. A full answer would convert to_i and then divide:
(Time.now.to_i - 23.hours.ago.to_i) / 86400
>> 0
(Time.now.to_i - 25.hours.ago.to_i) / 86400
>> 1
(Time.now.to_i - 1.day.ago.to_i) / 86400
>> 1
In the question's specific example, one should not parse to Date if the time passed is relevant. Use Time.parse instead.
Very late, but it may help others:
end_date.mjd - start_date.mjd
https://apidock.com/ruby/Date/mjd
Hint: This works only for Date objects, not Time objects.
To have the number of whole days between two dates (DateTime objects):
((end_at - start_at).to_f / 1.day).floor
The best solution currently that I've seen work consistently well is using the following pattern:
(end_date.beginning_of_day - Time.now.utc.beginning_of_day).seconds.in_days
To get the number of days difference by two dates:
(start.to_date...end.to_date).count - 1
or
(end.to_date - start.to_date).to_i
(end_date - start_date)/1000/60/60/24
any one have best practice please comment below
def business_days_between(date1, date2)
business_days = 0
date = date2
while date > date1
business_days = business_days + 1 unless date.saturday? or date.sunday?
date = date - 1.day
end
business_days
end
I have 2 independent but contiguous date ranges. The first range is the start and end date for a project. Lets say start = 3/21/10 and end = 5/16/10. The second range is a month boundary (say 3/1/10 to 3/31/10, 4/1/10 to 4/30/10, etc.) I need to figure out how many days in each month fall into the first range.
The answer to my example above is March = 10, April = 30, May = 16.
I am trying to figure out an excel formula or VBA function that will give me this value.
Any thoughts on an algorithm for this? I feel it should be rather easy but I can't seem to figure it out.
I have a formula which will return TRUE/FALSE if ANY part of the month range is within the project start/end but not the number of days. That function is below.
return month_start <= project_end And month_end >= project_start
Think it figured it out.
=MAX( MIN(project_end, month_end) - MAX(project_start,month_start) + 1 , 0 )