Using MDX in SSAS tabular get first 10 days of each month - ssas

I am trying to dynamically get the dates, starting from begging of month to current date using SSAS Tabular - DAX, I have tried many date functions but I couldn't end up with solution, so is there any idea to share pls ?

The following DAX function will return a table of DATES for each day from the start of the current month through today:
DatesMTD = CALENDAR(DATE(YEAR(TODAY()), MONTH(TODAY()), 1), TODAY())

To be able to filter the dates for the first 10 days, create a calculated column that identifies as a date in this range
1st to 10th Date = If(Day([Date]) <11,1,0)
This can then be used to either filter out the dates past the 10th of each month

Related

SQL query to find week number based on days of week in Oracle

I need to find the week number of given date based on days of week.
For example:
I am trying using the below query, but unable to calculate it based on the day.
select
to_char(to_date('20150101','YYYYMMDD')-2,'iw') week_sun_thru_saturday,
to_number(to_char(to_date('20150101','YYYYMMDD')-1,'iw')) -
to_number(to_char( to_date('03-jan-2015','dd-mon-yyyy')+1,'iw')) week_from_03_jan_2015
from dual;

How to get the data for the last 12 months and split and month-wise in HIVE?

Table format for the date column is "yyyyMMdd" and I'm using the following functions to convert into standard format so that HIVE day, months and year can be performed to get the respective values.
(from_unixtime(unix_timestamp(cast(created_day as STRING) ,'yyyyMMdd'), 'yyyy-MM-dd'))
To get the current year data, I would subtract the year obtained from all the records with the year returned by the current date and if it return zero, then it falls in this year.
(year(current_date()) - year(from_unixtime(unix_timestamp(cast(created_day as STRING) ,'yyyyMMdd'), 'yyyy-MM-dd'))) = 0
Problem: If the current date falls in January, I would get only January data month, but i need to get the data from February(last year) to January(current year)?
Also I need to scale this to obtain the last 24 months.
I always set my date range parameters outside of Hive and pass them as arguments as this lends itself to reproducibility and testability.
select <fields> from <table> where created_day between ${hiveconf:start_day} and ${hiveconf:end_day}

datepart in sql on year change

I am using datepart function in SP. It is used to compare week and year of specified date.
Now my query arise as new year starts. I have one table called 'Task' and it is storing tasks date wise. Now When I execute SP with DATEPART(YY,'2016-01-05') . It is giving proper 2016's data. But I execute it with DATEPART(ISOWK,'2016-01-05') , it is giving 2015's data also with 2016's data.
I want data from 28th dec,2015 to 2nd jan,2016. Data of the week. And I am not able get data of 1st and 2nd Jan in that. Please help me with this.
Thanks,
ISOWK return the week number
You are trying to get date from 2015-12-28 to 2016-01-02.
The week number of 2015-12-28 is 53 and 2016-01-02 is 53
If you already have your start and end dates decided then you could use a simple query as shown below to filter on date range.
When mentioning date string in your query make sure you stick to this format :yyyymmdd which SQL Server will automatically understand. You don't need DATEPART to get records between two dates.
Query for filtering on a date range
SELECT TaskID, TaskDescription
FROM Tasks
where TaskDate between '20151228' and '20160102'
Another query you can use for date range filtering
SELECT TaskID, TaskDescription
FROM Tasks
where TaskDate >= '20151228' and TaskDate <= '20160102'

how to summarize sql result, week and month wise in single query

I want to summarize sql query result week wise and month wise at the same time in a grid view. Is this even possible or I am just dreaming?
Requirement:
Show last one month data and next two month's data week wise in the grid.
Example-
If the current month is September then I want to show data from 1st August to 31st October categorized in weeks.
Show the data after the next month of current month in month wise view in the same grid.
Example-
data for month November and December will be shown categorized in month not in weeks.
grid or result should look something like below -
Please suggest something to achieve this
If you want a maintainable solution, use two independent queries, one for weekly aggregation other for monthly. Depending on the input run corresponding query.
I think you must work with group by or group by ... cube
SELECT x , y from <tabel> GROUP BY date_feld( to_char( 'MM' ))
but i don't now your DBMS so i can't give you a exact example for the date handling.

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.