Plotting the number of days between two dates by month - powerpivot

I have a table of 'events' in powerpivot that contains an 'End Date', 'Start Date' and a 'Length' in days.
I can currently plot a pivot chart from this data showing the sum of 'Length' by 'End Date' or 'Start Date', but how do I create a measure that will allow me to plot the 'Length' by month, where only the number of days that fall within that month are counted?
For example, if a record has an 'End Date' of 1/11/2018, and a 'Length' of 10 days, then the measure should put 9 days in October and 1 day in November.
I have set up a 'dates' table to give me the month etc., with a relationship to the 'End Date' in the 'events' table.

for excel check: solution
for power bi check: Solution

Related

Teradata - How to Look up value based on today(date) from table C then filter Dates from Table A

I am a complete novice at this so please go easy on me, i have found some examples on here but have yet to be able to get them to work.
I have two tables:
Table C lists, Date, Financial Year - Financial Year is text and might look like "Year 21" if the date was 31 August 2022 and "Year 2022" if 1St September 2022 the exact date it changes is somewhat dynamic year on year but is stored in this table correctly.
Table A lists the main Data and includes columns like Store, item, Cost, Date - it does NOT include the financial year and i need it too.
I can join the Financial Year column by matching the dates from the two tables. Simple.
What I need to do is then show only the data in table A from Weeks 1 to the most recent week of the CURRENT Financial Year
Just now i have pulled the last full 6 weeks, but this wont be helpful in WK5, this would pull wk52, WK1 WK2, and so on.
Below pulls the correct data for the last 6 full weeks but i need it to pull everything in this Financial year which can be determined by looking up today against C.THE_DATE and returning the C.YEAR_NBR
I hope that makes sense? i'm probably over complicating all this, including the below so thoughts and feedback welcome!
SELECT
A.WEEK_NBR as "Week",
C.YEAR_NBR as "Year",
A.PERD_TO_DT as "Date",
A.LOC_NBR as "Store Number",
A.ITM_NBR as "SKU",
oreplace(A.ADJ_REAS,'Code 55','Audit Adjustment') as "Adj Reason",
SUM(A.ADJ_QTY) as "Adj Qty",
round(SUM(A.ADJ_CST), 2) as "Cost",
case when A.ADJ_REAS = 'Code 55' then round(SUM(A.ADJ_CST), 2) else 0 end as "Audit Cost",
case when A.ADJ_REAS = 'Code 55' then SUM(A.ADJ_QTY) else 0 end as "Audit Qty"
FROM MICROST.weekly_losses_item A
JOIN PRODUCT.CALENDAR as C on A.PERD_TO_DT = C.THE_DATE
WHERE A.PERD_TO_DT between NEXT_Day(CURRENT_DATE - 49,'Sunday') and NEXT_Day(CURRENT_DATE - 7,'Saturday')
AND A.ADJ_CST <>0
AND A.ADJ_QTY <>0
GROUP BY A.LOC_NBR, A.ITM_NBR, A.ADJ_REAS,A.WEEK_NBR, C.YEAR_NBR,A.PERD_TO_DT

BigQuery, Sum by week

I am using standard SQL and am trying to add the weekly sum for product usage by week.
Using code below, I was able to add to each row the respective week and year it falls into. How would I go about summing the totals for an item by week and outputting it in columns, say up to the last 8 weeks.
extract(week from Metrics_Date) as week, EXTRACT(YEAR FROM Metrics_Date) AS year
Image is my raw data with the week and year next to an item:
This image is of above raw data being analyzed further(grouping them together). Here is where I would want to add columns, current_week & firstday of week date, and a sum of that weeks totals.
Any help would be appreciated.
You don't need the extract() by the way, you can do truncation DATE_TRUNC(your_date, WEEK) and it will truncate it to the week, usually easier.
Also, because the result of the truncation is a date, you will have the first day of the week already.
The rest I believe you have it figured out already, but just in case:
SELECT DATE_TRUNC(your_date_field, WEEK) AS week, SUM(message_count) AS total_messages FROM your_table GROUP BY 1

NetSuite Wookbooks Running Total Sales for this year vs. previous year

I am trying to make a chart in NetSuite using Analytics Workbooks which shows sales for certain reps this year vs. previous year.
I've tried this in a number of different ways but it does not seem like this is possible without using formulas. I am not very savvy in writing code as I am just getting into this.
Type is Sales Order AND Sales Rep is any of ...,...,...,...
The goal is to have a shaded line chart for this year to date vs. last years sales for a group of reps.
Edit:
The closest I can get to a chart showing cumulative data is a column chart with separate measures for each month. This gives a year next to year instead of a year over year.
Original:
This formula will give you the criteria field for your date range:
CASE WHEN TO_CHAR({trandate},'DDD') <= TO_CHAR(CURRENT_DATE,'DDD') AND TO_CHAR({trandate},'YYYY') >= ( TO_CHAR(CURRENT_DATE,'YYYY') - 1) THEN 'T' ELSE 'F' END
Set this to "Yes" on the Criteria tab.
For the Series, use: TO_CHAR({trandate},'YYYY')
For the X-Axis, use:
Month: TO_CHAR({trandate},'MM-MON')
Week: TO_CHAR({trandate},'WW')
Date: TO_CHAR({trandate},'MM/DD')
Here is a list of TO_CHAR date options
Here is my chart layout

DAX Counting Values in previous period(s)

I have a Month Column with the Month Field populated for each line for the 100K of lines of data I have.
I need to count the amount of times the Month Field is populated in the Previous Month (Period).
I also need to count the total amount of times the Month Field is populated in the Previous 11 months as well.
This is a rolling count for each months reporting that I do..
table name: 'ws pds' and field name [Month Tagged]
You can utilize the powerful time intelligence functions in DAX such as PARRALLELPERIOD to look at values from previous months. But in order to make use of these functions you need to create a calendar/date entity. Mark that entity as a Date table. And join to it by date from your "ws pds" table. The Date dimension should span the timeframe of your date with a continuous list of dates, one row per day.
Then your measure could look like this:
PreviousMonthCount=
CALCULATE (
COUNTROWS ( 'ws pds' ),
'ws pds'[Month Tagged] <> BLANK (),
PARALLELPERIOD ( Calendar[Date], -1, MONTH )
)

Pass the monthly value of an SSRS report chart into another report with date from and date to parameters

I have a yearly chart that it broken down into the 12 months Jan - Dec. The report contains various parameters including a yearly dropdown that changes the chart and report.
This all works fine within the first report.
The problem is that I have set up an action on the chart to go to a second report with a monthly breakdown, so my question is how can I pass the monthly value from the first report to the second?
The monthly report has an additional date from and date to parameter, so for the month of January it would need the values: Date From: 01/01/2010 and Date To: 31/01/2010 for example.
Thanks in advance.
Since you have the year and month integer values, you can construct the start and end dates to pass to your other report using expressions.
The start of the month will be:
=DateSerial(Fields!Year.Value, Fields!Month.Value, 1)
Where Year and Month are the integer values from the Chart/Dataset.
The end date is a bit more complicated; since the day part can be 30/31, etc, but we can just add one month to the above expression to get the first of the next month, then go back a day:
=DateAdd(DateInterval.Day
, -1
, DateAdd(DateInterval.Month, 1, DateSerial(Fields!Year.Value, Fields!Month.Value, 1)))
This way your drillthrough report can get its date based parameters and you don't need any changes to your dataset/parent report.