Fetch the data from sqlite database with multiple columns and rows - ios

I am creating an app for iPhone in which I am using sqlite to create a database. I wrote a query in which it returns 4 columns with multiple rows.
First column have values like indian territory(NORTH,SOUTH,EAST,WEST), in Second column it have the states name which belongs to these territory. There is almost 4 states in each territory. It may increase after some time. Third and fourth column have some no data which is belong to that state. How to show If I clicked in south territory then it should show all the south states in tableview. How to match the state names with its territory and fetch data according to that.
Now I have to add all states according to territory, please not give me static code like Territory= INDIA EAST, because if territory increases than it will fail.
I have to add all states into different arrays according to its region like all south in one array and all north in one array and so on..

We could use a look at your schema, but a query like this sounds like it would work:
select states from my_table where territory = 'NORTH'
You can run sqlite3 from Terminal and execute queries there, which will help you concoct your queries. Also I suggest looking at FMDB, which offers a nice API to help interface your code to SQLite. It has excellent documentation which will help translate your query's results into ObjC/Swift data structures.

Related

Joining of non-unique cells across multiple columns in Google Sheets

I have some personal data with first/last names, e-mails, institutions people work at, etc. There are many, many duplicates because this was collected from a few sources over 2-3 years. Sometimes the same person provided different versions of their name, a different e-mail address, etc. I'd like to have a compact version of this data, where a single person (identified by a PersonID) is listed on a single row, with unique variants of their name, e-mail, etc. listed in each cell. Bonus points if the values in every cell are sorted, but far from required.
Example above also available at https://docs.google.com/spreadsheets/d/1jizgysC1dntZHg8pZ0--dSAPevSfyXyiVyenj02GiwQ/edit#gid=0
I'm looking for a way to display the unique values in each column of a filter result, ideally staying away from =QUERY if at all possible.
This is easy to do when working with just one resulting column:
=FILTER(A4:A9,D4:D9=1) --> =JOIN(", ",UNIQUE(FILTER(A4:A9,D4:D9=1)))
...but the moment the filter spits out results in multiple columns:
=FILTER(A4:C9,D4:D9=1) --> ???
...I have no clue what to do, other than doing the code above for each column separately (which would be a hassle, given the number of columns involved). Is this possible?
Here's one way to do that using MAP:
=MAP(UNIQUE(D4:D),LAMBDA(id,BYCOL(FILTER(A4:D,D4:D=id),LAMBDA(col,JOIN(CHAR(10),UNIQUE(col))))))
By stablishing a column in I with unique values (=UNIQUE(D4:D)), you can use this MAKE ARRAY:
=MAKEARRAY(COUNTA(I4:I),COUNTA(F3:H3),LAMBDA(r,c,
JOIN(CHAR(10),FILTER(INDEX(A4:C,,c),D4:D=INDEX(I4:I,r)))))

How to generate a distribution based bar chart on row_numbers

I have a SQL query that acts as a data source in my tableau desktop:
SELECT
row_number() over (order by sales) as rn,
article_number,
country,
SUM(sold_items) as si,
SUM(sales) as sales
FROM data.sales
WHERE sales.order_date between '2021-01-01' and '2021-12-31'
GROUP BY 2, 3
On tableau I dragged rn to column and sales to row to generate a bar chart. The following is the output:
I want to convert this into a 0-100% distribution chart so that I can get the following result:
How can I achieve this? Also, I want the user to filter by country level so even if the # of records increase or decrease, the distribution should always be consistent with the filtered data.
You can do this with nested table calcs.
For example, the following uses the Superstore sample data set, and then first computes a running total of SUM(Sales) per day, then converts that to a percent of total. Notice the edit table calc dialog box - applying two back to back calculations in this case.
The x-axis in this example is Order-Date, and in your question, the the x-axis is a percentage somehow - so its not exactly what you requested but still shows that table calcs are an easy way to do these types of operations.
Also, realize you can just connect to the sales table directly, the custom sql isn’t adding any value, and in fact can defeat query optimizations that Tableau normally makes.
The tableau help docs explains table calculations. Pay attention to the discussion on partitioning and addressing.

Google Datastudio show empty row combinations

I am creating a Google Data Studio report for a car dealership and I have a problem.
I have made these 3 screenshots to illustrate:
If you see on the first screenshot, the datasource is pretty simple, used/new indicates weather the car being sold is new or used and if it is a sportscar or family car, and exchange/clean deal indicates weather the dealership takes/buys the customers old car in for a trade off in price. The rest should be self explanatory.
On screenshot2-3 you see my report, I have one table for each salesperson and it shows the amount of sales for each combination that has sales.
The problem is this, I want the tables to show each combination even if it does not have any sales at all, it should just show 0 then in record count. Like Mike on the left has more combinations than john, I still want Johns table to show those combinations just with a 0 then, and it should be sorted the same on each table so they look the same, just different data in the cells.
Is this possible to do?
To solve this problem, you need to make a combination of data, from the database with itself. Your main analysis dimension, which will generate your combinations, is used/new and Exchange/Clean deal. So your combination should be:
The filter defined in the second database (right base) must contain a filter telling which person the table will be destined for. So, for each table, you must make a new combination that contains the person-specific filter.
I just took a sample from your original database (10 first lines) and the result is:

States VLOOKUP on a continuously added to Google Sheet

Ok I have been fighting this for a few days now... and ever time I think I have it I don't.
I have a Google Sheet that is continuously being added to from different sources. It is collecting orders from several e-comm outlets. I organize the data to come in generally how I need it from the sources. I them am taking that data and putting it into Data Studio. But since the sources are different, the State field comes in in many different formats, but I need them to all be the same, preferably abbreviations. I have been trying to do a VLOOKUP on a Named Range created in a separate sheet that has all the variations of states that I have seen in column 2 and the abbreviated version in column 1. Then in my main data sheet I am doing a big formula in row 1 of the column that I am trying to output the state abbreviations.
Here is the formula:
=ArrayFormula(IF(ROW(B:B)=1, "Shipping State Abbv", IF(C:C = "US", IFERROR(VLOOKUP(B:B, StatesList, 1, TRUE), B:B), B:B)))
Note: There are some countries other than US, so if it is not US I just want the value from Column C.
I have created a small sample of data that is showing what is happening here. If someone could please help me figure out what is wrong and help me fix it that would be fantastic!
Another Note: The sheet States List 2 is another format for laying out the different versions of the states, if that could utilized instead, that may be nicer to maintain. Basically find the value in the sheet and use column 1 as the returned value.
I think I found what was going on, as your vlookup was not doing a very good job.
Basically I just copied the values from States List to States List 2 and swapped the columns A and B on the States List 2:
Then updated the value of the function to this:
={"Shipping State Abbv"; ARRAYFORMULA(IF(LEN(A2:A),if(C2:C = "US",VLOOKUP(upper(B2:B), 'States List 2'!A:B,2,FALSE),C:C),))}
Let me know if you manage to succeed.

Dynamic Currency Conversion in Google Sheets

I'm using Google Sheets to organize data from my global royalty statements. Currently I'm querying several tabs (one for each country) to produce a single table with results from all countries. As you can imagine, I don't want 125 Japanese Yen showing up in my charts and graphs as $125 USD (125 Y is equivalent to about $1.09 USD).
Since I receive my royalty statements in their respective currencies, I'd like to apply average conversion rates either during the query operation or after the fact. Since the table is being generated dynamically, the values won't always be the same, so I need some way to apply the conversion by searching the list of currencies on the fly. I've got a separate table on the same tab containing all the average conversion rates for each currency. Here's a sample of how this is set up:
So basically I just don't know how to say, in coding terms, "If this line item comes from the UK, divide the royalty amount by the UK exchange rate. If it comes from Canada, divide by the Canadian rate, etc."
Anyone have any insight as to how I might pull this off (or whether it's possible)? The actual table includes over 500 line items from a dozen different countries, so doing this by hand is something I'd like to avoid.
I believe you are looking for the GoogleFinance() function. You may want to set the Country to a pick list of the valid country entries so you could create the string for the conversion. I have not looked at many, but this will take a value in CA & and apply the exchange rate to convert it to the US $ Equivalent. The exchange rate in this case is an average of, I believe, the past 30 days.
=C2 * GoogleFinance("CURRENCY:CADUSD" , "average")
For your use, you can get the country code from row M if you change it to match what the formula is after, such as CAD for Canadian Dollars."
=C2 * GoogleFinance("CURRENCY:" & M2 & "USD" , "average")
Another option would be to create a lookup table and use VLOOKUP or some other function, depending on how you set up your table.

Resources