Summing inside Redshift UDF - amazon-web-services

I have a dates tables, columns:
date: the date e.g. '2018-06-29'
business_day: 1 or 0 to indicate if date is business day or not
I want to create a User-Defined function in Redshift that outputs between two dates how many business days. In a select statement is will look like :
select business_days(start_date timestamp, end_date timestamp) as integer
for example:
2018-06-29 is a friday business day
2018-06-30 saturday non business day
2018-07-01 sunday non business day
2018-07-02 business day
select business_days( '2018-06-29', '2018-07-02') should output 2
Redshift does not allow aggregates inside a function and I am looking for a workaround.

Amazon Redshift User-Defined Functions cannot access the network, nor can they access data stored in tables.
As an alternative approach, you could create a Python function that can calculate the difference between two dates.
If you merely wish to skip weekends, you could Count number of days between dates, ignoring weekends.
If you have more complex logic, such as skipping holidays that vary by year, you will need to supply that information to the Python function, such as including the special dates within the function itself (eg in a list of holiday days).

Related

Create a date filter showing 12 rolling calendar months starting from EOM

I have a process where I have relationship between my sales table and my custom date table. My sales data gets its' filter from the custom date table. I have a process where I have 3 refreshes in 3 consecutive days starting from EOM of "previous month" and show last 12 calendar months.
I start this process end of every month i.e. For February data report I start on 02/28/2023 that will be my first refresh to filter sales data for last 12 calendar months (03/01/2022-02/28/2023). The next following day (03/01/2023) the second refresh need to filter (03/01/2022-02/28/2023).Then the final refresh is the next following day (03/02/2023) also need to filter (03/01/2022-02/28/2023). I couldn't use the standard filters in PBI since the eom is an exception. I have tried to create custom table using a formula where I add 7 days to today(02/28/2023) so I can go forward in time for my first day(02/28) and come back a month so I can get whole 12 calendar months. This wouldn't matter for the next month(03) since 7 days is not going to make any difference for month filter. I tried below custom table formula however it didn't work. Perhaps there is a better way to handle the exception indicated below
Table = CALENDAR(DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()+7)),TODAY())

Power Pivot - Is it possible to setup a date relationship to a table with a FROM and TO date

I have been searching the internet for support with this but cannot find anything that fits the bill. I'm not sure if what I want to do is possible, so if someone can please help
I have a table of employees which contains a column 'FTE' (Full Time Equivalent) with an effective date from and effective date to. The FTE changes based on the dates from and to.
I want to create a data model that allows me to work out FTE daily and aggregate using Pivot into Weekly/Monthly/Yearly FTE
If an employee is full-time, they will show as 1.0 FTE with the dates that reflect the time they were 1.0. So example, 01/04/2022 to 31/07/2022 - this will show as 1.0 and 1 row in my data. I want to be able to calculate FTE on a monthly basis by multiplying the FTE by the number of days in the month, so potentially 31 FTE days
I'm struggling to understand how to create a relationship between the employee table with the FROM and TO dates on my date table.
A workaround that would work but is too inefficient is to create a full list of dates for each employee in PowerQuery first as this will generate 2+ million records

Trying to make a date slicer which includes both date and time

I have a table of many datetime datapointname value triplets from process probe sensors.
I want to have a slicer which I can use to pick from time1 on day 1 to time2 on day 2
So my approach has been to have three slicers [Time Start] [Date Slicer] [Time End]. I have the data table and two time tables in 30 minute intervals so I have been able to create measures and display cards to show on the report the start and stop datetime combo.
I try to combine all this into a new table using DAX which filters the data table using the measures that I have but have not had any success.
Does anyone how how to set up a slicer or set of slicers so I can filter my report (for example), from 2022-Jun-15 at 4:30 PM to 2022-Jun-18 at 10:00 AM?
I am just learning about DAX. I have spent a few hours at this with no sucess.
Thanks
That's probably not a good idea from a modelling perspective. Data modelling best practice suggests that your Date (where 1 row = 1 day) and Time (where 1 row = 1 second or 1 minute, as necessary) dimension tables should be separate.
I would therefore recommend you setup your model in such a way that you have these two dimensions as two separate tables. You should then just be able to have two slicers - one from each table - to do what you need.
Note: this of course means that your fact tables will need to have separate columns (one for the date and one for the time) to join to your Date and Time dimension tables.

how to set current quarter in Superset?

I want to set current quarter dynamically, e.g [2021-01-01 ~ 2021-04-01)
Does superset support it? if so how to config it?
The Last vs Previous and date range control in general has been a source of confusion for my users.
Last Quarter just shows the last 3 months [because it's a quarter of a year?].
It would be great to have options like Week to date, Month/Period to date, Quarter to date, etc...
Another issue is that each company may define their quarters/periods on different starting dates, depending on their fiscal calendar.
As a stop-gap, I've done the following.
enriched the underlying dataset to have additional columns like period_start_date and fiscal_quarter_start_date.
created a fiscal_dates table that contains a list of every day over the years I need to query. The columns correlate with date columns in my other tables, like dob, fiscal_week_start_date, period_start_date, fiscal_quarter_start_date . I created this table in postgres using generate series
created a new virtual dataset that contains the column period_start_date, that shows the last 4 years of period start dates.
use a value native filter to select from the list of dates.
make the values sorted descending, and default value as "first item in list".
This allows the user to select all records that occur in the same quarter/period, with a default of the current quarter.
The tentative apache/superset#17416 pull request should remedy this problem, i.e., for the QTD you would simply specify the START as datetrunc(datetime("now"), quarter) and leave the END undefined.

power BI relative date filter

Relative Date Functionality in Power BI:
Issue #1:
Hi Team,
Need to know is there any way to implement the below relative date filter functionality in Power BI
Please note the following:
For year the base year should be current year, for now it should be 2021
For month the base month should be current month, for now it should be july and so on.
Issue#2:
Based on the above, we want to implement a functionality based on the below selection, where in if we select week, then we should see the count of a metric only for the weeks which are passed by the above filters and similarly for months, days etc. For eg, if we select year, then we should get the count for the year 2022 only as this is the only year passed by the above filter.
Thanks for any help!
Technically possible? I think so. Feasible? No, not really.
While there is some playroom with bookmarks, custom graphics and clever use of a wide range of measures and calculation groups - it would be an enormous task to get everything running correctly and smoothly.
Perhaps one option is to introduce this filtering functionality via a custom visual that takes your date column as input?