set up the default value to be the most recent pay period taking into account the date or the the most recent year - data-science

I have a discreate column ( Pay Period number ) from ( 1 - 26 ) & another column ( Date ) ( 2010, 2011 ,.... , current ) .
I already have filter in the dashboard ( Pay Period number ) . However I want to set the default value to be the most recent Pay period taking into account the most recent year also. How can I connect the date column with the pay period column
Thank you for your help

Related

Select subscription date range

How to turn a date into last month's date?
SELECT extract(day from (Select (period_start) from accounts where id = 'id')) AS "Day of month";
The above give me the day of the month
Account Table
id (primary)
startPeriod
User records
timestamp
account_id (foreign key)
The user is registered at 02-12for subscription start
I would like to have a query to select the date range from the current month to last month
This current month is April, so I would like to select the record that is
select records from table where date > '03-12-2022'
get the subscription start period and get the date
set the query limited to last month with the subscription start date
how to produce this date 03-12-2022 which is driven by subscription start period and previous month?
many thanks
This approach should work:
Get the number of months between the subscription date and today e.g. age(timestamp1, timestamp2)
Get the number of months and subtract 1 to get last month e.g. duration = extract(month from age(timestamp1, timestamp2)) - 1
Add the months to the subscription date e.g. (subscription_date + (duration || ' month')::INTERVAL)

Most recent instance between dates

What I currently have...
What my goal dataset should look like...
As you can see, I need a new column that takes the rows where Type = "Repair" and places the date of the most recent date where Type = "PM". Example above shows repairs 11/19 & 10/26 so I would need the 9/29 Date since it's the most recent PM date. For repairs dated 9/8, 8/21 & 8/5 I would need the 7/26 PM date since it's the most recent PM date before those repairs. This would be the pattern for many months of data. Thanks!
After adding the recommended Windows function this is what I get
You can use a window function:
select t.*,
(case when type <> 'PM'
then max(case when type = 'PM' then date end) over (partition by id order by date)
end) as most_recent_pm_date
from t
This assumes that you want the most recent date per id.

Default prompt for date using month names from month numbers in OBIEE 11G analysis

Our database has a field for months as periods 1,2,3, . . . and a field for years. I would like the prompt to have month names instead of digits and I would like to have a prompt for my analysis that defaults the prior month from the time the report was run. I have year and month working in digit format(works for every month except if run in January) but I can't seem to get a solution that works with month names defaulting to the prior month.
The months need to be Year to Date, so <= the prior month.
I am in accounting so it is to get the ledger for the last day of the prior month. Each period month has just the activity for that month, so Prior year is 0, Current year activity is <>0 and the balance as of the month is 0 through the prior month.
I want users to be able to change the selections if they need but have defaults selected that they will use 99% of the time.
Right now, with the period numbers I was using
SELECT "Date"."Fiscal Period Nbr"
FROM "General Ledger"
WHERE "Date"."Fiscal Period Nbr" = (VALUEOF(Current_Month) - 1)
And for the years
SELECT "Date"."Fiscal Yr Nbr" FROM "General Ledger"
WHERE "Date"."Fiscal Yr Nbr" = (VALUEOF(Current_Year))
I created a group for each month selecting the periods, so January is 0,1 and February is 0,1,2 and so on. In the prompt I select those 12 groups and was trying to do some sort of SQL for the Default selection.

Selecting sets of data and creating a new column in SQL Server

In SQL Server can you select the first set of values (i.e. week numbers 1 - 52) give them another value in a new column, then select the next lot of values.
The problem I am having is the data table I am working on has week numbers for each financial year, which starts the first Sunday after 1 October. So it simply iterates 1 - 52 for each financial year.
I am trying to make a column in a view that grabs the first 52 gives them the a financial year value of 1, then grabs the next 52 and gives them a financial year value of 2 etc (obviously with year 1 starting at the first record). I do have the Week Ending Date column to work with also.
Here is a snippet of the table:
Is this possible?
Leave the Sundays and Octobers. If I understand correctly, you only need to assign a rank to each occurrence of week number in order of the ending dates.
Please try this (but use copy of the table or transaction to check first; of course T is name of your table):
update T
set fiscal_year = YearNumbers.FiscalYear
from T
inner join
(
select WeekEndingDate, WeekNumber, DENSE_RANK() over (partition by WeekNumber order by WeekEndingDate) as FiscalYear
from T
) as YearNumbers
on T.WeekEndingDate = YearNumbers.WeekEndingDate and T.WeekNumber = YearNumbers.WeekNumber

use of week of year & subsquend in bigquery

I need to show distinct users per week. I have a date-visit column, and a user id, it is a big table with 1 billion rows.
I can change the date column from the CSVs to year,month, day columns. but how do I deduce the week from that in the query.
I can calculate the week from the CSV, but this is a big process step.
I also need to show how many distinct users visit day after day, looking for workaround as there is no date type.
any ideas?
To get the week of year number:
SELECT STRFTIME_UTC_USEC(TIMESTAMP('2015-5-19'), '%W')
20
If you have your date as a timestamp (i.e microseconds since the epoch) you can use the UTC_USEC_TO_DAY/UTC_USEC_TO_WEEK functions. Alternately, if you have an iso-formatted date string (e.g. "2012/03/13 19:00:06 -0700") you can call PARSE_UTC_USEC to turn the string into a timestamp and then use that to get the week or day.
To see an example, try:
SELECT LEFT((format_utc_usec(day)),10) as day, cnt
FROM (
SELECT day, count(*) as cnt
FROM (
SELECT UTC_USEC_TO_DAY(PARSE_UTC_USEC(created_at)) as day
FROM [publicdata:samples.github_timeline])
GROUP BY day
ORDER BY cnt DESC)
To show week, just change UTC_USEC_TO_DAY(...) to UTC_USEC_TO_WEEK(..., 0) (the 0 at the end is to indicate the week starts on Sunday). See the documentation for the above functions at https://developers.google.com/bigquery/docs/query-reference for more information.