Sumif Last date value in powerpivot - powerpivot

I'm working with excel 2016 and have already loaded my data in PowerPivot
My data is as below (summarized):
Date Time Amount
9/20/2017 8:20 100
9/20/2017 9:20 200
9/20/2017 10:20 180
9/21/2017 9:00 50
9/22/2017 22:00 110
All I want is to create a measure so that for each date, I sum the last Amount value (indicated in bold); so in the example, the desired value would be 290.
Thanks in advance

You can calculate the latest Time by day, and then use this in a measure.
Find the maximum time of date:
mymaxtime=CALCULATE(MAX(myfact[Time]);filter(myfact;myfact[Date]=EARLIER(myfact[Date])))
You can then use this calculated column in a new measure:
mycalculation:=CALCULATE(sum(myfact[Amount]);filter(myfact;myfact[Time]=(myfact[mymaxtime])))
Screenshot of the result:

Related

Return date after each month cut off date in Presto SQL

I have encountered this situation where I need to return a specific date for each cut off automatically. The cut off will be 5 days before each month.
Desire output :
Start from Jan 1, the calculation of transaction will be between 2023-01-01 and 2023-01-26
eg. from this period there are 100 transactions from 10 users.
Then the date will automatically start again between 2023-01-27 and 2023-02-23
eg. from this period there are 200 transactions from 20 users.
and so on..
So, basically the data will returns on each cut off
Any help would be appreciated!

MySQL: How to Count total orders by hour from a specific date range

Customer_placed_order_datetime
01 00:00:20
02 01:00:00
31 23:59:00
I want to count the total number of orders that has been made every hour from 01 - 31 days
example outcome:
01-31 HOUR total_orders
1st hour 500
2nd hour 400
Many RDBMS have functions to format dates and cast to string.
For example, with PostgreSQL, you can use TO_CHAR(date_value, string_format). With this new format date (ask only the yyyyMMdd), you can group and count your orders.
If you tag your RDBMS, I can help you more precisely

How can I handle a Julian Date rollover in SQL?

I have a list of julian dates that I need to keep in order ex. 362, 363, 364, 365, 001, 002, 003. My query starts with getting the last julian date processed and each date after that. Right now it will max my lowest date out at 365 and I can't get the records that follow it. The same set of data also has a date field with the year attached but it doesn't seem to be helpful since those records won't be gathered until the rollover is corrected. Here is my simplified query:
select JulianDate, RecordDate
from table
where JulianField > #LowestJulianDate
and RecordDate between GetDate() and DateAdd(day, 6, GetDate())
Sample date:
JulianDate
RecordDate
362
2020-12-28
363
2020-12-29
364
2020-12-30
365
2020-12-31
001
2021-01-01
002
2021-01-02
003
2021-01-03
Desired output:
JulianDate
362
363
364
365
001
002
003
So if you'll imagine we start on day 362, our #LowestJulianDate is 362, and our record date range is today and the next 6 days, completing that list of julian dates.
How can I get the dates to go in order and resolve in a rollover?
You cannot by just using the "JulianDate" which is actually the DayOfYear value. You would need to also store the year that it refers to either separately or as part of the "JulianDate" value. For example, instead of "362" you need "2021362".
well why not sorting by year column and Julian date column ?
select JulianDate, RecordDate
from table
order by yearcolumn,JulianDate
What we are doing in the case of not having a year and wanting to sort a list on the year rollover for a 7 day rolling window is looking at the left 1 of the Julian day. If it's less than 3 roll it's rolled over. We sort into 2 baskets (old year and new year), order them, then recombine them with the new year's data being the "greatest" in the list.
We look at the left 1 because in our application, the last day of data we get may be 357 and the rollover may be 003 for example.

Excel: Insert blank row if non consecutive date

We have a process at work that runs every 31 hours and would like to have a column in an Excel 2010 spreadsheet that reflects the time and dates the process is due to run each day over the coming year e.g.
start date (Cell:A1):
10/31/2016 1:00
11/1/2016 8:00
11/2/2016 15:00
11/3/2016 22:00
11/5/2016 5:00
11/6/2016 12:00
11/7/2016 19:00
11/9/2016 2:00
11/10/2016 9:00
11/11/2016 16:00
11/12/2016 23:00
11/14/2016 6:00
I am currently using the formula: A2 =A1 + (31/24) to populate the dates and times in the column which appears to work ok. I need to insert a blank row between days that are not consecutive (in order to highlight that fact, to make it easier for the operators to read and not instigate the process at the wrong time!) which is where the difficulty lies. I am assuming that I will need a separate VBA function to step through each cell and compare the day date (ignoring time value.) in the previous cell, if day date is greater than 1 (as in not the following day.) insert a blank row.
I am looking for a solution to the following scenario but am struggling to get my head round it and would appreciate any guidance/ help anyone is able to provide.
Many thanks
You do not need a VBA Function for that, it can be accomplished with the function
A3 = IF(A2="",A1+31/24, IF(INT(A2+31/24)=INT(A2)+1,A2+31/24,""))
*For that to work, you will have to populate cells A1 and A2 manually, though.
You can use the INT() function to get the date part of a DateTime field, so it becomes simple to check if adding 31 hours will leave a 1 day gap in the sequence by checking INT(A2+31/24) = INT(A2)+1.
So, to explain the function, the part
IF(INT(A2+31/24)=INT(A2)+1,A2+31/24,"")
will check if the days are consecutive, and if so, it will fill the DateTime. If not, it will leave it blank.
The outer IF checks if the cell above is blank. If it is, the function will use the one above that.

Counting days at the place

I am working on the crystal report Xi and my problem is in my report I have to show the count of the days patient spend on one place, they can get transfer any number of times or they don't get transfer even one time. So every time they transferred from their admission to discharge I want to count of days on that place the patient spend.
PatID Admission Discharge Place TransferPlace TransferDate
121 05\06\2013 06\01\2013 102 105 05\10\2013
121 105 101 05\20\2013
121 101 108 05\25\2013
Here I just created a data the patient first transfer on 05\10\2013 from 102 to 105 that means he was at 102 since he got admitted (4 days) and in 105 he was for 10 days.
I hope it should be clear.**
Try DATEDIFF() function it will return the date difference
To get the difference between dates you use the DateDiff function. In your case you want to get the amount of days between the dates, you would use:
DateDiff(day, {Admission.Date}, {Transfer.Date})
{Admission.Date} and {Transfer.Date} are the date fields you would be using in your report.
EDIT:
So I think you can make this work using the PREVIOUS function in Crystal. Try something like:
if isNull(previous({Transfer.Date}) then
DateDiff(day, {Admission.Date}, {Transfer.Date}) else
DateDiff(day, previous({Transfer.Date}), {Transfer.Date})
You could also go the other way by using the NEXT function.