I have two dimension field say [Custom Date] which have data like 'September 2009' and [Custom Date With Formart] which have data like 'Sep-09'.
I am applying order function to arrange it as shown below.
Order(BottomCount(
{[CUBE].[Custom Date].[Custom Date].ALLMEMBERS}, 12),
[CUBE].[Custom Date].[Custom Date].[], DESC)
ON COLUMNS,
It arranges my dates as 'September 2009','October 2009'....,'January 2010','February 2010'.
Order(
{[CUBE].[Custom Date With Formart].[Custom Date With Formart].ALLMEMBERS},
[CUBE].[Custom Date].[Custom Date].[], DESC)
ON COLUMNS,
Output for above is like 'Jan-10','Feb-10',....,'Sep-09','Oct-09'.
What i want is to display [Custom Date With Formart] on axis and sort it using [Custom Date].
Let me know your comments.
Thanks to all of you. I resolved my issue by following this link.
I'm not sure to really understand your issue. Why do you need any specific ordering to get what seems to be
the natural ordering of a time dimension. In any case, it might be that you need to use the BDESC option instead of DESC (see documentation here).
You could try creating a string to sort on, and converting it to a date, if you can cope with VBA:
ORDER(whatever, CDate("01-" + [my dimension].currentMember.caption), BDESC)
That code may not run as it is, but what I'm trying to suggest is that you take the string of your member name "Sep 10" and turn it into a string with a full date in (first of the month), which can then be converted into a date, and used to sort on.
Related
I am working with a FitBit daily activity dataset within BigQuery. I have a date column (stored as a date type), and I'm trying to make a new column that will reflect the days of the week (Saturday, Sunday, etc) alongside the original date column. I'm still fairly new to SQL, so I'm not sure how to do this. This is what I've tried:
Attempt #1. I also tried to use the DATENAME function, but I kept getting an error message. Anyone who can point me in the right direction will be much appreciated!
Use below
select ActivityDate,
format_date('%A', ActivityDate) as day_of_week
from your_table
with output like
I am working on a SSRS report which compares data of 2 given months. I'm categorising the chart based on Day and time in the following format 1, 6:00 AM. I get this column from the T-SQL itself. But the axis does not come properly. It looks like below now which doesn't make sense. I want it to be in order from 1st to 30th with the time component.
I guess I need some kind of sorting on X-axis with respect to date time. Please help!
After deleting from sorts from chart I'm getting some extra repitive dates after comparing all 30 days of both months. Data from the query looks alright to me!
Thank you!
Ok. Large query
You X-axis are show value in format date,hh mm tt Right ?
Then you want to sort them with day number 1 - 30.
From your query I suggest you add 1 field is like this CAST(SampleCollected AS DATE) [orders] and use this field in Order in Query or Sort on SSRS (not recommend ) and if you use Order in Query must delete sort condition on chart sort.
But if result still not you want try to add MONTH(SampleCollected) As MonthG to order again like this
ORDER BY MONTH(SampleCollected),CAST(SampleCollected AS DATE)
Hope it's Help.
I would like to calculate Sum(QTY) until the start date of the month for a given date.
Basically I can calculate Sum(QTY) until given date in my measure like:
SumQTYTillDate:=CALCULATE(SUM([QTY]);FILTER(ALL(DimDateView[Date]);DimDateView[Date]<=MIN(DimDateView[Date])))
But I also would like to calculate Sum(QTY) for dates before 10/1/2015 - which is the first date of selected Date's month. I have changed above measure and used STARTOFMONTH function to find first day of the month for a given date like;
.......DimDateView[Date]<=STARTOFMONTH(MIN(DimDateView[Date]))))
but not avail, it gives me
"A function ‘MIN’ has been used in a True/False expression that is
used as a table filter expression. This is not allowed."
What am I missing? How can I use STARTOFMONTH function in my measure?
Thanks.
STARTOFMONTH() must take a reference to a column of type Date/Time. MIN() is a scalar value, not a column reference. Additionally, your measure wouldn't work, because STARTOFMONTH() is evaluated in the row context of your FILTER(). The upshot of all this is that you would get a measure which just sums [QTY] across the first of every month in your data.
The built in time intelligence functions tend to be unintuitive at best. I always suggest using your model and an appropriate FILTER() to get to what you want.
In your case, I'm not entirely sure what you're looking for, but I think you want the sum of [QTY] for all time before the start of the month that the date you've selected falls in. In this case it's really easy to do. Add a field to your date dimension, [MonthStartDate], which holds, for every date in the table, the date of the start of the month it falls in. Now you can write a measure as follows:
SumQTY=SUM(FactQTY[QTY])
SumQTYTilStartOfMonth:=
CALCULATE(
[SumQTY]
;FILTER(
ALL(DimDateView)
;DimDateView[Date] < MIN(DimDateView[MonthStartDate])
)
)
I am working on a SSRS report that displays Date, Time and few other columns.
My SP returns just Date Column (which has time part in it) and a few other columns.
In the report I want to group by Date Part and show all details including the time (I used formatting option "T" to display only Time in Date column) in the details group.
For grouping on Date I used:
=FormatDateTime(Fields!TxDate.Value, DateFormat.ShortDate)
Which seems working. However if I try to sort on other columns it is not working. Any thoughts/suggestions on this?
It might be easier if you were to add an extra column into your dataset that was based on your original date+time column but containing just the date. Then you can use this to do a simple group on that column.
For example, if the dataset is based on a SQL query and your date+time column is called [Date], then add another column in the query as CONVERT(DATE, [Date]) AS DateOnly or something similar.
I've got a table with purchase orders stored in it. Each row has a timestamp indicating when the order was placed. I'd like to be able to create a report indicating the number of purchases each day, month, or year. I figured I would do a simple SELECT COUNT(xxx) FROM tbl_orders GROUP BY tbl_orders.purchase_time and get the value, but it turns out I can't GROUP BY a timestamp column.
Is there another way to accomplish this? I'd ideally like a flexible solution so I could use whatever timeframe I needed (hourly, monthly, weekly, etc.) Thanks for any suggestions you can give!
This does the trick without the date_trunc function (easier to read).
// 2014
select created_on::DATE from users group by created_on::DATE
// updated September 2018 (thanks to #wegry)
select created_on::DATE as co from users group by co
What we're doing here is casting the original value into a DATE rendering the time data in this value inconsequential.
Grouping by a timestamp column works fine for me here, keeping in mind that even a 1-microsecond difference will prevent two rows from being grouped together.
To group by larger time periods, group by an expression on the timestamp column that returns an appropriately truncated value. date_trunc can be useful here, as can to_char.