SQL Server 2012 - date not sort as expected - sql-server

Alright, I searched each and every option upon SQL related to sorting a date column. Most of them say that it's not correctly sort because the column is of type nvarchar. This is not my case.
My table and query:
.
Injection aside, as you can see in the image, I want the column that I selected in the image to be in correct order - the 7th column (I am sorry for the native column name); however, it is not. To be more precise, that 1660 row is not sorted correctly, while all other rows stay in the line.
I tried ascending order, and as you may guess it, it's that 1660 row that stays in the last regardless of other row's value.
I also tried sorting by other columns with similar type - 6th, 8th and 9th, and they're working fine.
The 1660 row doesn't have any special column, nor its date is any special. It just between lots of other rows, between June and July.
These time columns are inserted using vb.net through a DatetimePicker value.
So can someone shed me some light into this case, as to why, how, or what is the cause of this disorder... It's driving me nuts.

Your 1660 row has a date in the year 2106, not the year 2016. This is obvious from looking at the image. It is not a formatting error or a sorting error; it is a typo in your actual data.

Related

Data Studio - Grouping by Week

I have a simple Data Studio table consisting of two columns. The first column is the week (ISO Year Week) and the second column is the total registrations we've received for that week.
However, my Week column repeats 7 times (7 Rows) for each week as it's counting by day within that week. See below:
Is there any way to get this to group by the listed week? Below are my settings:
Dimension = Conversion Date set as "ISO Year Week" for the type.
Metric = Equals the count of Conversion Date (Same Conversion Date field used for dimension)
Any help would be much appreciated.
There might be an issue with the date format of the source. Without knowing the source (e.g. Google Analytics or Sheets) it’s hard to tell.
Blended Data
I recently had this issue with blended data. The response of a similar question helped me to find a way.
Basically you have to add a new custom field to the data source with the formula WEEK(date_field_link). Data studio will recognise this as a date in compatibility mode, but for me it still works. Then you can use this new date field as a join key to blend the data while grouping it in weeks.
Normal Data
If this problem appears in a regular non-blended dataset you might want to check if Data Studio correctly catches the date as a date. This help article from Google might be worth checking out: https://support.google.com/datastudio/answer/6401549?hl=en#zippy=%2Cin-this-article
I made a similar case work using blended data.
Your column "Conversion Date" repeats the same week 7 times because it's just a display value. Every row has a date value (year, month and a day) but you're just showing the corresponding week. So, data-studio treats them as different data and doesn't group them.
To be able to group them by Week you need to create a new field with a value containing only the week and the year. So, you can use the formula
YEARWEEK(your_date)
The resulting Date will be groupable.
NB1: If your date isn't of the type Date, you can parse it from text to date using
the method:
PARSE_DATE("%Y-%m-%d", your_date_text)
NB2: If the created field has the type number and doesn't show the possibility to change type to Date, you can do this trick: (it's weird but it works):
First type as a formula for the created field and apply:
MONTH(your_date)
This will unlock the compatibility Date types. You can choose from them the ISO Year Week type.
and then change the formula from MONTH(your_date) to YEARWEEK(your_date) [your formula] as I explained above. The chosen date type won't go away even if it wasn't available the first time.

Where does the last value and blank date come from?

I have encountered a strange thing in my power pivot table and chart. I have the EUR/SEK in a table and chart and as you can see here
the last value is above 70 and the date is blank-blank-blank. I have obviously checked my table and there is no blank row or value above 10.3.
Do anyone know why I have this strange value and blank date?
Best regards
Okay so this one was stupid simple. I thought I had checked everything that could go wrong but I hadn't. So the problem was all the time that my dynamic calendar hadn't update correctly and so there was values for like 7 days or so that didn't have matching dates in the calendar. These 7 or so values accumulated under blank and therefore gave me the strange chart.

Creating composite dates from individual year, month, and day in Google Data Studio

I need to create a YYYYMM format computed column for defining a date in Data Studio since our data is held in separate year, month, and day columns. Unfortunately our the month and day fields are not left zero-padded so a simple concat will not work.
The formula I'm using still uses concat, but also uses todate to parse the hyphenated date string into the compatible format.
TODATE(CONCAT(systems.added_year, CONCAT('-', concat(systems.added_month, concat('-', systems.added_day)))), 'DEFAULT_DASH', '%Y%m')
The problem I'm running into, is that Data Studio doesn't seem to correctly recognize the resultant value, even though it seems to be correct. I'm not sure why, but the YYYYMM field seems to one-month behind even though the result of the calculated field looks correct.
In fact it seems 1-day behind, if I show YYYYMMDD the displayed value is the last day of the previous month.
Here is a screenshot showing the component elements, a string version of the calculated field, and then a Date(YYYYMM) version of the calculated field.
Looks like a bug with the output format. As a workaround, you could output as a full date and then change the column format to YYYYMM.
TODATE(CONCAT(year, CONCAT('-', CONCAT(month, CONCAT('-', day)))), 'DEFAULT_DASH', '%Y-%m-%d')
You could also use '-01' as the last segment.

SSAS 2012 DAX SamePeriodLastYear() with Date Dimension

I have a date dimension and a fact table. I have two measures:
WorkOrdersCount:=
count(
FactWorkOrderLifeCycle[Clientsid]
)
and
WorkOrdersLastYearCount:=
CALCULATE(
count(FactWorkOrderLifeCycle[Clientsid]),
SAMEPERIODLASTYEAR(DimDate[FullDate])
)
WorkOrdersCount is simple and works fine. I thought WorkOrdersLastYearCount would be simple as well, but I now realize I don't understand SAMEPERIODLASTYEAR().
My date dimension has a DateSID column containing an integer representation of date as YYYYMMDD. It has two recordkeeping rows with SIDs of -1 and -2 for unknown and TBD dates. I'm only using the -1 row in this solution. The data is stored in a SQL Server table and the FullDate column is a "date" type. The actual value is 1900-01-01.
My fact, FactWorkOrderLifecycle, has a field called InvoicedDateSID that can have a null value which I replace with -1.
No errors are thrown in Visual Studio or when processing the olap, but upon referencing the column in a pivot table I get the following error:
ERROR - CALCULATION ABORTED: Calculation error in measure
'FactWorkOrderLifeCycle'[WorkOrdersLastYearCount]: An invalid numeric
representation of a date value was encountered.
Things I've tried (not all make sense):
changed SID values to positive integers
changed date value in dimdate to 9999-12-31 instead of 1900-01-01 when I saw that DAX dates might start at 1900-03-01
adding other dimensions to the pivot first to see if the formula calculates correctly at all.
I'm a DAX noob and I'm not sure how to troubleshoot this. Any help is appreciated!
Make sure you calendar table is indeed using a Date data type.
Remove any time component of your dates.
Make sure there are no gaps and no duplicates in your Calendar table.
Make sure you are using fields from your Calendar table on the pivot, and NOT date related fields from your data table.

Excel - find value in row which is not an error or blank

Someone posted a question about doing this for a column but I don't understand the answer well enough to tweak it to work for data in a row. Can someone help me understand how this formula works and how to apply it to data in rows? I want to display the non error value in a new column, not the number of the row or column.
Thanks!
Try this formula
=LOOKUP(2,1/(A1:A100<>""),A1:A100)
extend range as required. In Excel 2007 and later you can use the whole column
Original question here: Excel - find last value in a column which is not an error or blank
=LOOKUP(2, 1/(A1:G1<>""),A1:G1)
Just change the range in both places.

Resources