Sorting by Date After Mult-IMPORTRANGE and QUERY - sorting

Have a Google Sheet that I'm trying to build. It uses IFTTT to pull articles people read into a individual, and then an aggregate spreadsheet.
In terms of specs, it needs to:
Pull in data from multiple sheets.
The first column in each source sheet is a date column. Some are formulas (to remove extraneous data from another date column), and some are hard-coded. This may differ sheet to sheet, but is constant per sheet.
Once imported into the aggregate sheet, I need to sort by date.
Problem
I'm a query/importrange newbie, and I'm currently stuck on the sorting by date.
Current URL
https://docs.google.com/spreadsheets/d/1GLGYvApJgRheg7rgzoB8rFyTUgkRpZ2O8eKVE4bZyo4/edit?usp=sharing
When I order by Col1, I can't honestly tell how it is sorting, the end result is:
March 7, 2017
February 15, 2007
February 28, 2017
March 7, 2017
March 8, 2017
November 9, 2010
If you inspect the cells, the first March 7, 2017 is situated where the formula resides, which does not seem to move no matter how I sort. If you look at the sort order without that cell, it seems to be sorting alphabetically.
So it comes down to two main questions:
-What am I doing wrong that is making it so the order by is not including the first row.
Edit: This is now fixed
-How do I get it to recognize that the contents of the sorting column is a date?
Thanks ahead of time -
J.

Your formula seems to have a few problems.
importrange should take key not url. But it seems that it works anyway...
Pulled sheets have no header, so the 3rd parameter of query should be -1 or omitted, not 1.
If Col1 is a valid date, <> '' should not work. It should be is not null.
But it turns out that your pulled sheets' dates are not yyyy-mm-dd format so they weren't recognized as dates by query.
Thus, more valid formula should be like this:
=query({importrange("...", "Sheet1!A:E");importrange("...", "Sheet1!A:E")},
"select * where Col1 is not null order by Col1 asc",
-1)
And you should format dates(column A) on your pulled sheets to yyyy-mm-dd. Check my working sample aggregator and pulled sheet one and two.

Related

Excel Power Query storing the old data in a column

In excel power query I have a linked excel file where only the last column is updated by the team. For example is the cut-off data day is Jan 13th then the data is titled Jan 13 and the rows are updated for this week. When the update is done the following week, the column header is changed to Jan 20. How can I keep the old data for Jan 13th in power query so that I only get the new data in a new column when refreshed?
I tried but I am stuck
PowerQuery doesn't store any data, it's essentially a transformation script, that uses whatever is in the linked source when refreshed. So if the data for 13th is gone at the source it will be gone in PowerQuery too. If the column for 20th is added next to column for 13th, then you can create a dynamic logic that would keep more columns.
You could create a logic preserving the historical data using VBA (to store it in the not linked table), but in Excel & M it is not possible. With PowerBI there is an option of incremental refresh that potentially could be used here, but it's not available in Excel

Microsoft Power BI, DAX - tricky ALLSELECTED with 2 values in slicer, but show only TOP 1 row in visual

This question is an extension of an already answered question, which I posted this week.
I have the below situation in Microsoft Power BI.
I have 2 simple tables:
1) CountryTable
2) YearTable
There is a 1-M relationship between YearTable and CountryTable.
The latter (YearTable) is used to feed values into a slicer.
(In my client database, Year has some alphabetical prefixes, such as Q1-2022, so I prefer to use YearOrder column to sort the Year column at the backend, while the slicer will display the Year column.)
The former (CountryTable) is the main table, with just a few sample rows.
These two tables are related via the Year column.
The Year slicer always has EXACTLY 2 values chosen in my Power BI report.
I need the Maximum of these two values of the year slicer as a measure, for each row of my visual.
At the same time, these two year values of the slicer must remove the unwanted rows in my report visual, based on the slicer selection of year values.
For example, when the slicer has 2019 and 2020 chosen, I need the value as in the DesiredOutput1 page.
Similarly, you can see DesiredOutput2 (Slicer values are 2020 and 2022); DesiredOutput3 (Slicer values are 2019 and 2022) pages.
I have indeed successfully obtained DesiredOutput1, DesiredOutput2, DesiredOutput3. Thanks to all the folks who helped me attain this.
Now, my main requirement in this posting, is this:
After obtaining the DesiredOutputs above, I need the following output:
Show only the TOP 1 row (ASC order of Year column, which is the minimum value of the slicer).
Essentially:
Year column of the visual: Minimum value of the slicer
MaxYear_Measure_SlicerSelection: Maximum value of the slicer (maximum of the two values chosen in the slicer)
You can see below:
Note: MaxYear_Measure_SlicerSelection measure can refer to any one of the two measures [MaxYear] or [MaxYearMeasure_Community] (see the .pbix file for the formulas of the measures).
Any idea ?
I prefer the Year column of the visual not to be converted to a new measure. Would RANKX help in this case ? Any thoughts?

Filtering date column in Visual Studio SSIS ( Derived column)

I want to filter a column that spans from 2014-2019 to 2017-2018 in VS with SSIS.
I have tried different things but none seem to work.
Derived Column date in your example is likely what you're looking for.
The Week column is of a date type DT_DBDATE. Your string "2017-01-01" should be getting promoted to a data date type so the boolean check will identify if the lower bound is being met.
You'd either need to create a second derived column to check against the upper bound or as #vhoang indicates, change the logic to just extract the year from the date column.
YEAR([Week]) >= 2017 && YEAR([Week]) < 2019
Now, you have a column that flags each row as meets criteria or not (year is 2017 or 2018)
You will then need to do something with that. The SSIS something is called a Conditional Split. I would add a new path called OutOfConsideration and the logic there would be the inverse of our above Derived Column Derived Column date which is true if the year meets our criteria.
![Derived Column date]
Now connect your destination, or additional processing steps, to the Conditional Split's default output path. If you need to do processing on the invalid data, that'd be the OutOfConsideration path.
Finally, to get the best performance out of SSIS, only bring the rows into it that you need. If the source data is in a system that supports filtering, filter the data there. It is easy to click click click design SSIS packages but it is better long term for you to write custom queries to only bring the required columns and rows into the data flow. Less work for all around, lower maintenance cost, etc

Sort Rows in Excel?

I have an issue with an excel spreadsheet I want to see if I can do without VBA just because it seems easier to implement that way. Basically, there are many columns in the sheet I want to sort. However, I merely want to look at three columns: the title column, the data column and the status column.
In a new spreadsheet, there will be four sections. Each section corresponds to 3 months of the year (ie Jan, Feb, Mar. will map to the first column on the new spreadsheet, April, May, June will map to the second column on the new spreadsheet).
Based on the date, and if the status column has the word "Finished" (in the original spreadsheet), I want to map the title to a certain column under the new spreadsheet based on the date criteria as described in the previous paragraph. So for example, if the original spreadsheet has following:
Title Date Status
Doc1 1/12/13 Finished
Doc2 2/10/13 UnFinished
Doc3 4/1/13 Finished
Doc4 3/31/13 Finished
Would map to, on the new spreadsheet:
1st Column | 2nd Column
Doc1 Doc3
Doc4
I have looked a lot into pivot tables but I can't "automate it" as much as I want to. I have gotten it down to the point where I can change the pivot tables into filtering based on date, but I want it even more automated than that. I've also tried excel formulas but that has been to no avail. Thanks for the help, I really appreciate it!
With a PivotTable it seems fairly easy to 'automate' as far as Sheet 2 as below:
but from there to the result requested is relatively 'manual' without VBA, so may not suit.
For my convenience I have changed the date formats. The PivotTable is constructed as usual/indicated without showing grand totals for rows or for columns (PivotTable Options, Totals & Filters). The Column Labels are Date with Grouping By Quarters with appropriate Starting at: and Ending at: (Group) and Collapse Entire Field (Expand/Collapse).
The formula in I6 is to convert the document count (always 1) to document name:
=IF(F6=1,$E6,"")
However, to allow room for additional quarters in the PivotTable the formula should be moved to the right. The formula would need to be copied across and down as necessary.
The process becomes more ‘manual’ with copying the results of these formulae, pasting them (with Special / Values) into a new location (in the example 2!A1) and, if required, deleting blanks.
This may be against the rules with regards to maintaining the integrity of the OP's request, but hopefully it doesn't offend :)
Here's another option.
Add another column (shame on me, I know) to the original data, and
called this Quarter. The formula that goes next to the existing data
is the following.
=IF(C2="Finished",IF(MONTH(B2)<=3,"Q1",IF(MONTH(B2)<=6,
"Q2",IF(MONTH(B2)<=9,"Q3","Q4"))),C2)
Basically, if the status is "Finished", then determine in what quarter the date is.
Create the pivot table with that data, and then add "Quarter" and
"Title" to the Row Labels (in that order)
Last thing would be to click the arrow next to "Row Labels" and select "Does not Equal" under "Label Filters". There you'll type "Unfinished" (no quotation marks). This will give you something like the image below.
From here the only manual thing you'll need to do is update the data range for the pivot table if more rows are added to the pivot table data and refresh the pivot table if the original data changes
NOTE: To address your question about sorting; after you do the steps above, you can select the Row Labels again and do an A>Z sort to get each quarter to be sorted in alphabetical order

SSRS Value By Date

Ok, I've seen similar questions on here, but nothing exactly the same. I am creating reports based on a cube that reads data from a DW. A lot of the reports tend to be along the lines of Value by Something By Week or Value By Something By Month. Everything seems ok, but the week and month (columns) don't order correctly. Week 10 goes before Week 9, February comes before January, etc. Im very frustrated bc I can't get these things to work correctly.
To add to this, at some point my customer needs to be able to write their own reports against the cube using Reportbuilder 3.0. So, I am reluctant to rely on manually editing the query. SURELY there is some obvious way to do this. In my DimDate I have a weekname that is a varchar, a week that is date, etc. Same for month.
Im missing something obvious here.
Thanks!
The sort order would make sense (varchars are strings {"Week 10", "Week 9"}, and {"February", "January"}) in that they are coming before their respective pair in the examples you've given, assuming an ASCII type of sort on the string values.
There are multiple ways to have ascending sort with strings as column headers (assuming ASCII type sorting on the string field):
Ensure week numbers are two digits in length e.g. "Week 9" would become "Week 09". This will ensure that the week columns are sorted in ascending order (or descending order, which ever is the case).
Add a month number in front of the month name e.g. "01 January", "02 February" -> You will still need two digit month numbers otherwise you will get the same issue you had with week numbers.
Use formatted dates as opposed to strings, as dates will be sorted properly.
Alternatively, if the issue is being caused in the dimension within the cube you can ensure any order by clauses are on keys, and not name fields.

Resources