To Get YEARMONTH from date in Athena - amazon-athena

I can get year and month separately in Athena but i don't know how to get YEARMONTH from date.
select year(date1) from table1
select Month(date1) from table1
Please suggest how to get YEARMONTH. Thank you in advance.

You can use date_format to represent your date in needed format:
select date_format(now(), '%Y%m')

Related

How to add two date columns to query in teradata sql?

I want to add two date columns, run_date and report_date to my existing query, what is the best way to do this?
select
*,
current_date as run_date,
Add_Months(Current_Date - Extract(DAY From Current_Date), 0 ) as report_date
from my_final_table;
will the run_date and report_date appear in my last two columns from the data set? Thank you!

Power BI From and To Date Filtering with One Slicer

I've a simple (hope so) question.
I've got a table where I have a start date column and an end date column.
I can add two slicer to filter the period, but I would like to filter with just one slider, like shown on this video https://www.youtube.com/watch?v=W5n8-5Q7mII&ab_channel=RADACAD but I'm missing the point of creating the other date table like he does. Can someone else help me? Thanks in advance
You can create the date table using Power Query or Dax.
https://radacad.com/all-in-one-script-to-create-date-dimension-in-power-bi-using-power-query
https://radacad.com/all-in-one-script-to-create-calendar-table-or-date-dimension-using-dax-in-power-bi
Simply you can use CALENDAR() or CALENDARAUTO() function in Dax.
Date = CALENDAR(<start date>, <end date>)
Date = CALENDARAUTO()
Those will help you create the date table.

Power BI - Get the Days of current Month

I have a column "Days of Month" which is just rows from 1 to 31 and a filter above with the date as you can see in the screenshot below. I want to filter this column to show me the days of each month based on the filter above.
For example if the date above is 2/2/2020 i would like to see 28 rows on my column.
I tried several solutions but i couldn't achieve this.
Can anyone help me ?
I was able to get this working by duplicating the date table and creating a relationship to its duplicate on year and month.
Add a [YearMonth] column to your date table
Duplicate the Dates table as Dates2
Create a many-to-many data relationship between Dates and Dates2 on the [YearMonth] column. Set the cross filter direction to Single (Dates filters Dates2)
Set up your report to use a slicer or filter on Dates[Date] and display Date2[Day] in a table visual. Here is the result:

Columns in each table - Year, Month and YearMonth. How can I create a calendar table? In PowerBI

I have three columns Year, Month and YearMonth on each data source table.
Example,
Year - 2020
Month - 3
YearMonth - 202003
Data type and format of these columns are Whole number.
How can I create a common Calendar table which can be linked to the YearMonth column of the each table to make a relationship.
Is there any way?
Thanks in advance!
In PowerQuery
Reference one of your source tables
Select the Year, Month and YearMonth column
Remove other columns
Remove duplicate rows
and here's your calender table. You only need to set up relations between all the YearMonth columns and then you can hide Year, Month and YearMonth in all source tables.

AWS Athena date sql query

Below is the data in csv file in s3 bucket which I have used to build Athena database.
John
Wright
cricket
25
Steve
Adams
football
30
I am able to run the query and get the data.
Now I am trying to fetch date of birth based on age column. Is it possible to generate date of birth from age column like current date - age (column) and print only the date of birth?
I tried below query but not sure whether it is correct way
select (current_date - interval age day) from table_name;
Please help me with this.
You can use the date_add function, like this:
SELECT date_add('year', -age, current_date) FROM table_name
I.e. subtract age number of 'year'(s) from the current date.