Dealing with repeated fields - google-app-engine

I'm storing a log on the server with multiple lists where I store some data such as dates and information associated to these dates. The first field of the first list corresponds to the first field of the rest, the second field of the first list to the second field, and so on.
Using the FLATTEN function I managed to show this information, but it shows a combination of the whole data on the lists. Having 4 lists 3 fields each, generates 12 different rows.
Is there any way to show only three results, by order on the lists?

I don't love this solution, but it's the first idea that comes to mind that solves your problem:
SELECT dates, lead, userID FROM
(SELECT NTH(1, dates) WITHIN RECORD dates, NTH(1, lead) WITHIN RECORD lead, userID
FROM [egolike.com:egolike-production:egotest.egoViews]),
(SELECT NTH(2, dates) WITHIN RECORD dates, NTH(2, lead) WITHIN RECORD lead, userID
FROM [egolike.com:egolike-production:egotest.egoViews]),
(SELECT NTH(3, dates) WITHIN RECORD dates, NTH(3, lead) WITHIN RECORD lead, userID
FROM [egolike.com:egolike-production:egotest.egoViews])
WHERE dates IS NOT NULL
Basically we are mapping the Nth value of a column within a record to the Nth value of the other column. A drawback is the need of explicitly calling each Nth place by number. Hopefully you can re-import the data with a different structure! (One repeated column, containing the aligned records)

Related

SSIS/visual studio- using derived column transform to count distinct values and sort by two variables?

I have three columns of data- incident_ID, date, state.
The incident_ID are each unique, date is in year format only and ranges from 2013 to 2016, states are in no particular order and repeat if an incident occurs w/in the same state in the same year.
I'm going to be combining this data w/ another table, but first I need to organize the data to better match the other table's format- which is laid out showing the year, state, and dollars spent per state. So for 2013, I would have 51 rows (each state + DC) and each state would have a dollar amount- then rinse/repeat down the table through to 2016.
I'm pretty new to SSIS/Visual Studio, but from my understanding I should be able to use a Derived Column Transform to accomplish this.... but I don't know how to get there.
Is there a way to use Derived Column to 'count' and rearrange the data in order to show how many incidents occurred per state in the given year?
There is no aggregate (like SUM,Count,Min,Max) functionality in Derive Columnenter code here.For count, you can use ROW COUNT Task or you can insert the data into SQL table and then you can call the result value in derived column.

Create a Table based on results of a column of data in another worksheet and eliminate null values

To set this up....I have roughly 12,000 rows of data that captures sales detail activity. I have an Excel function in a column to the right of the data that identifies the invoice number based on unique qualifiers (if the transcation meets the qualifier it lists the invoice number and, if not, assigns ""). Of the 12,000 rows of data maybe 50 will qualify. I then need to use the invoice numbers that qualify to pull sales and COGS data for all those invoices that match the qualifying invoice numbers (another explanation is necessary at this point....an invoice that qualifies will be listed twice....once that contains the information that identifies whetehr it qualifies but that row will have no sales data and a second time with thye dsales data...I do not know why it does it this way. So, in other words, the row of data with the sales information I need to capture does not contain the data that allows me to recognize that an invoice qualifies). Each mopnth adds the current month's sales data to the population...so, 12,000 rows this month and it will be 16,000 next month and so on.
I was hoping to create a table that pulls only the qualifuying invoice numbers from the sales data (it would basically create a table of 50 (in my example) while ignoring the 11,950 rows where the cell equals ""). I can do a simple pivot table but next month I need it to recognize the new population of data and update based on the additional rows of new monthly data as well as the rows of data from prior months.
Any soultions/ideas are much appreciated!

MS Excel - Find Missing Date values between two dates in a column full of dates

I have a master list of SKUs in one table set as a column with a different SKU listed in each row.
I have another table with a daily snapshot of items which I have in stock between 7/1/17 and 7/31/17 in each row. The table shows the item SKU in one column, the warehouse where there is quantity in another column, and the quantity available within that warehouse in another column. There can be multiple occurrences of a SKU on one date if there are quantity in multiple warehouses. The table only lists SKUs on occurrences where there is quantity within a warehouse. If a SKU has no quantity within any of the warehouses on a date, it will not be listed in the table corresponding with that date.
In my table with the master list of SKUs I want to create a column that will show the the number of days within a range of dates (7/1/17 to 7/8/17) in which there were no quantity of the SKU being referenced available in any warehouse.
To show a more precise idea of what it is I am trying to do, I have posted a youtube video here: http://youtu.be/6CWLN6wzaWQ?hd=1
Have a look at the following URLs - I feel partially similar cases are discussed and resolved over there.
It will surely give you some lead to further work on.
How to return multiple values between two dates in excel?
https://answers.microsoft.com/en-us/office/forum/office_2007-excel/finding-missing-dates-in-column/8c49800a-6997-4585-b1f4-abdeaa64e718

Calculate value in column using value in previous column in SQL Server

I have a table A with SKU ID's, required dates and demand and another table B with current inventory positions. For each SKU ID, the inventory from table B will be the initial value and for each required date, I want to create two new columns, beginning inventory and ending inventory, which will get calculated based on the corresponding demand. I've attached an image with the output
I found a similar thread which used CTE recursion but it only applied to one ID. Given that I have multiple ID's, i would like the code to be dynamic and realize when all records for the previous ID have been exhausted so that for the next ID, it can pull a new beginning inventory from table B
Thanks
Desired Output:

Calculated Measure aggregating on certain cells only

I'm trying to figure out how I can create a calculated measure that produces a count of only unique facts in my fact table. My fact table basically stores events from a historical perspective. But I need the measure to filter out redundant events.
Using sales as an example(Since all material around OLAP always uses sales in examples):
The fact table stores sales EVENTS. When a sale is first made it has a unique sales reference which is a column in the fact table. A unique sale however can be amended(Items added or returned) or completely canceled. The fact table stores these changes to a sale as different rows.
If I create a count measure using SSAS I get a count of all sales events which means an unique sale will be counted multiple times for every change made to it (Which in some reports is desirable). However I also want a measure that produces a count of unique sales rather than events but not just based on counting unique sales references. If the user filters by date then they should see unique sales that still exist on that date (If a sale was canceled by that date if should not be represented in the count at all).
How would I do this in MDX/SSAS? It seems like I need have a count query work from a subset from a query that finds the latest change to a sale based on the time dimension.
In SQL it would be something like:
SELECT COUNT(*) FROM SalesFacts FACT1 WHERE Event <> 'Cancelled' AND
Timestamp = (SELECT MAX(Timestamp) FROM SalesFact FACT2 WHERE FACT1.SalesRef=FACT2.SalesRef)
Is it possible or event performant to have subqueries in MDX?
In SSAS, create a measure that is based on the unique transaction ID (The sales number, or order number) then make that measure a 'DistinctCount' aggregate function in the properties window.
Now it should count distinct order numbers, under whichever dimension slice it finds itself under.
The posted query might probably be rewritten like this:
SELECT COUNT(DISTINCT SalesRef)
FROM SalesFacts
WHERE Event <> 'Cancelled'
An simple answer would be just to have a 'sales count' column in your fact view / dsv query that supplies a 1 for an 'initial' event, a zero for all subsiquent revisions to the event and a -1 if the event is cancelled. This 'journalling' approach plays nicely with incremental fact table loads.
Another approach, probably more useful in the long run, would be to have an Events dimension: you could then expose a calculated measure that was the count of the members in that dimension non-empty over a given measure in your fact table. However for sales this is essentially a degenerate dimension (a dimension based on a fact table) and might get very large. This may be inappropriate.
Sometimes the requirements may be more complicated. If you slice by time, do you need to know all the distinct events that existed then, even if they were later cancelled? That starts to get tricky: there's a recent post on Chris Webb's blog where he talks about one (slightly hairy) solution:
http://cwebbbi.wordpress.com/2011/01/22/solving-the-events-in-progress-problem-in-mdx-part-2role-playing-measure-groups/

Resources