Total today, total yesterday ... total 7 days ago, total last week, average this month -data awareness in Power BI - date

I want an easy way to have a sum of yesterday, the day before and the day before that total 7 columns (past 7 days)
Then i would like average for L7D, Average LM.
I have made a column in my date that indicate what "today" is and then my idea was to have it sum if today, sum if today-1, sum if today-2 but this does not seem to work
)
Yesterday= CALCULATE(SUM('DanvægtLines'[NAV_Qty]);FILTER('DanvægtLines';'DanvægtLines'[Dato_Anden]>=TODAY()-1)
(It take the sum of quanto, then filters if the 2.date on the order is today)
It is only working with ">=" not if i only use "=" ... witch is ok for yesterday, but the if i want to have only 4 days ago i have to filter yesterday, the day before, and 3 days ago... witch make a very very long code line i dont get why
=(today()-4 wont work)

Ok so after about 15 hours of hair pulling it dawned on me that the table I was referring to was in the date+time format, so fixing that I could use =today()-1

Related

how to count week number of month using dataprep

I tried to count week number of month using below code,but I got weird num like -48.(I know my logic is weird lol)
Could you point out the fault of below code to make weeknum of month.
I need sensei's help.
I used Dataprep
WEEKNUM(date)-WEEKNUM(DATE(YEAR(date),MONTH(date),1))
no error , but some values are -48,47......
Your logic is mostly sound, except you're only thinking of WEEKNUM in the context of a single year. In order to have non-overlapping weeks, the week containing January 1 is always week 1 (regardless of the period), so in this case December 29–31, 2019 are all going to be week 1, just like the following 4 days of January will be. It makes sense, but only when you think about it in context of multiple years.
You can work around this for your case by checking the WEEKNUM and MONTH values conditionally, and then outputting a different value:
IF(AND(MONTH(date) == 12,WEEKNUM(date) == 1),53,WEEKNUM(date)) - WEEKNUM(DATE(YEAR(date),MONTH(date),1))
While hard-coding the week number of 53 is a little hacky, the whole point of week numbers is to always have 52 subdivisions—so I don't really see any concerns there.
You may also want to add 1 to the resulting formula (unless you want your week numbers to start with 0 each month).

SSRS - How to show rolling 6 months where the start date is always a Saturday?

I need help on calculating my start date for my report date parameters.
The end date will always be the last Sunday, here: =DateAdd("d", 1 - WeekDay(Today(), 1), Today())
What I need help with is how to write a formula to go back 6 months from today and pick the 1st Saturday in that range..
Thanks in advance.
Assuming your start day is a Sunday then you can use this...
=DATEADD(
DateInterval.Day,
7 - WEEKEDAY( DATEADD(DateInterval.Month,-6,Today()), FirstDayOfWeek.Sunday),
DATEADD(DateInterval.Month,-6,Today())
)
This works as follows
WEEKEDAY( DATEADD(DateInterval.Month,-6,Today()), FirstDayOfWeek.Sunday)
Takes today's date, subtracts 6 months and then finds out what daynumber that is. Running that today (2018-11-08) gives use (2018-05-10) which is a Thursday, this is day number 5
Saturdays are day number 7 (if your first day of week is a Sunday). As there can be no higher number than 7 we can do a simple subtraction of 7 minus the day number we landed on (from above) which gives us a required adjustment of 2 days.
Finally the outer DATEADD function simply says add our calculated 2 days to the date 6 months ago.
Hope that makes sense!?
If the first day of the week is not a Sunday for you then you may have to do some Mod% calc on the second argument to calculate the correct number of days to adjust by.

Filtering for dates less than or or equal to 9 months in the future in an Access query

Once a week I need to run a report where I query an Access database for any product that will expire in 9 months or less. The way they want it calculated is to take the date 9 months into the future and return anything that expires at the end of that month or sooner. If it were simply 270 days or less, I'd have no problem. (I'd also have no problem if I could do it in Excel, but that's not an option for now).
I came up with a solution that works every month of the year, unless it happens to be March (more specifically between March 6th and April 5th).
< DateValue(Month(Date()+270)+1 & "/1/" & Year(Date()+270))
So basically I'm:
adding 270 days to today's date
extracting the resulting month
adding 1 to the month
putting it back together as a text string so I can use < the 1st of the following month
for the year, I'm using the year from the date +270 days so I don't end up using the current year by accident
The trouble is that for the date range above (which I unhappily discovered today), I land in December when I add 270 days, so the following month is in a different year. As a result, my report only produced items that already expired.
In other words, on March 5th, I would have needed a list of everything expiring prior to December 1, but on March 6th, I need everything before January 1 of the next year.
Is there a more effective way to do this that avoids this issue? I thought of using
You may have had DateDiff in mind, and it can be used:
Where DateDiff("m", Date(), [YourDateField]) Between 0 And 9
However, that will ignore an index you might have on [YourDateField].
This, however, will include products that expired previously in the current month.
The alternative is DateSerial as Hans showed but he forgot that in SQL Date() must be used and that only those products that will expire should be listed:
Where [YourDateField] Between Date() And DateSerial(Year(Date()), Month(Date()) + 10, 0)
Use the DateSerial Function to compute the future date you need.
Here is a demonstration in the Access Immediate window which computes the date 9 months from today:
? Date
3/6/2015
? DateSerial(Year(Date), Month(Date) + 9, Day(Date))
12/6/2015
However, as I understand your requirement, you actually want dates from that entire month. In that case you can compute the first of the month which is 10 months from today and ask for everything less than that date.
? DateSerial(Year(Date), Month(Date) + 10, 1)
1/1/2016
You can include that expression in your query like this ...
WHERE expire_date < DateSerial(Year(Date()), Month(Date()) + 10, 1)

How To Calculate Date From Day Number In Excel

I have a small application built in Excel. It is a time management workbook where I record the hours worked on projects for each month.
In one column I have the possible days
e.g.
DAY 1
DAY 2
DAY 3
DAY 4
....
DAY 22
for the possible 22 workdays in a month. I have a worksheet for each month.
For each of those day numbers how would I calculate the date for that day in the Month?
You can try WORKDAY - Does the following helps?

Total Average Week using a Parameter

I have a crystal report that shows sales volumes called week to date volume. It shows current week, previous week, and average week. The report prompts for a date parameter and I extract the week number to get current week and previous week volumes. Did it this way because Mngmt wants to be able to run report whenever. My problem is for Average Week I cant figure out how to get the number of weeks to divide by for my average. Report originates from June 1st, 2010. Right now I have:
DATEPART("ww", {?date}) - DATEPART("ww", DATE(2010, 6, 1))
This returns 2 right now which is perfect, so i divide my total by 2. This code will work until the end of the year then I'm hooped. Any idea how I can make this a little more dynamic. I was thinking a counter somehow, just can't get the logic down because the date parameter will keep changing, meaning I cant increase my counter by 1 after each week???
Cheers.
Look into the Crystal Reports method: DateDiff.