SQFlite Database Order (ASC, DESC, Alphabetic) - sql-order-by

I have created a SQFlite database for my app which is working very well. Basically, the app is to create a list of my client's company details. The company name appears in an Expansion Tile, and once you open the tile, you see the rest of the company's details. I know how to arrange the tiles in either descending or ascending order, but is there a way to arrange according to alphabetic order based on the company name? Thus, can one arrange the tables in SQFlite in alphabetic order instead of ASC or DESC? When my client's details are added dynamically, I want them to be arranged in alphabetic order so that it makes more sense. Thank you so much for any help.. I have tried to find a comment on this on Stackoverflow, but don't seem to be able to find one.

Ok, I managed to figure this out. My question really shows my inexperience. Anyway, Query has a orderBy property. In my database I created the following code:
Future<void> _createDB(Database db, int version) async {
await db.execute('''
CREATE TABLE todo(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
name TEXT,
phone TEXT,
fax TEXT,
email TEXT,
street TEXT,
city TEXT,
town TEXT,
code TEXT,
isExpanded INTEGER
orderBy used to be 'id DESC'. It should simply be changed to 'title ASC'. Thus, it will order the sequence by the title in alphabetic order from top to bottom. Here is the code:
Future<List<Todo>> getTodo() async {
final db = await database;
// query the database and save as list of maps
List<Map<String, dynamic>> items = await db.query(
'todo',
orderBy: 'title ASC',
);
Thus, the correct question is not how to order in alphabetic order, but how to order based on title (which is the company name in my example) in ASCending order.

Related

Can't get Power Automate Filter Array to render distinct result

I've got 2 Arrays. One of the Arrays is a list of Office 365 Contacts. The other Array contains a list of Customers from an API. I've used a Select statement on my Contacts Array, so that it is in the same format as my Customer Array. When I create the following Filter Array, I never get the distinct item I'm looking for.
Here is the Code when I use Peek Code.
{
"inputs": {
"from": "#variables('Customers Arrary')",
"where": "#not(contains(variables('Contacts Array'), item()))"
},
"metadata": {
"operationMetadataId": "9ab3697e-6f5c-41b4-b94e-41641ce3dacf"
}
}
The result I'm looking for is to find all the items in the Customer Array that don't match to anything in the Contacts Array. The unique identifiers are email address and mobile number.
Any help is much appreciated! Thanks in advance!
I finally got this to work. In order for this to work, the data sets have to match. For example, if you are comparing two data sets against an email address, that's the only data you can have, and you better not have any null values. Here is an example filter I created. The JSON from the two arrays only contains email address values.
So, make sure and remove any data that does not appear in both data sets. I would also remove any items that contain null values.

DAX/POWERBI : count tickets attached to an item and all its child items

I am new to DAX and PowerBI and have a problem to write DAX formulas for my case:
I have two tables: Assets and Tickets. Each have an Id, and the Assets have a ParentAssetId (can be 0 or None).
In a DAX expression: I would like to count (and list) all the tickets attached to an Asset and its children.
I tried this way but without success:
nbChildTickets =
VAR mykey =
SELECTEDVALUE ( Assets[AssetKey] )
VAR mypar =
SELECTEDVALUE ( Assets[ParentId] )
RETURN
CALCULATE(
COUNTX(Tickets, Tickets[TicketKey]),
FILTER(Tickets, RELATED(Assets[ParentId]) = mykey)
)
The Tables and the Canvas
It is the asset table which contains both the AssetKey and the ParentId colums.
Have any idea or tuto to do this ?
Thanks
A question, are these tables already related? In case they are, it seems that you wouldn't need a measure like that to get the count of # of tickets by asset and its parent. I would do it in the next two ways. Supposing you need it in a table:
Option 1.
Create a simple count measure to get the number of tickets in Tickets table, it could be something like Number of Tickets = COUNTROWS('Tickets')
Drag a table to the canvas.
Add to the table Assets and its children columns, finally add your new measure to the table
Option 2. In case each ticket has an ID.
Drag a table to the canvas.
Add to the table Assets and its children columns. Also add your tickets Id.
At Fields section (where you drag and drop your columns, right click and select the Count option.
Done
Remember, it is important that your both tables are already related to work. Otherwise Power BI will not know how to calculate and displays this combination of data for you.
First create two relationships between Assets and Ticket table. One relationship will be active (one to many) on column AssetKey Column.
Second relationship will be Inactive. Asset[AssetKey] = Ticket[ParentID]
Now use the below Measures -
Number Of Tickets = COUNT(Tickets[TicketKey])
Number of Child = CALCULATE(COUNT(Tickets[AssetKey]),USERELATIONSHIP(Asset[AssetKey],Tickets[ParentId]))
Relationship diagram is in below image :
Output is mentioned below:
The blank row can be eliminated from visual filters :

Convert column value from null to value of similar row with similar values

sorry for the slightly strange Title I couldn't think of a succinct way to describe my problem.
I have a set of data that is created by one person, the data is structured as follows
ClientID ShortName WarehouseZone RevenueStream Name Budget Period
This data is manually inputted, but as there are many Clients and Many RevenueStreams only lines where budget != 0 have been included.
This needs to connect to another data set to generate revenue and there are times when revenue exists, but no budget exists.
For this reason I have gathered all customers and cross joined them to all codes and then appended these values into the main query, however as warehousezone is mnaually inputted there are a lot of entries where WarehouseZone is null.
This will always be the same for every instance of the customer.
Now after my convuluted explanation there's my question, how can I
-Psuedo Code that I hope makes sense.
SET WarehouseZone = WarehouseZone WHERE ClientID = ClientID AND
WarehouseZone != NULL
Are you sure that a client has one WarehouseZone? otherwise you need a aggregation.
Let's check, you can add a custom column that will return a record like this:
Table.Max(
Table.SelectColumns(
Table.SelectRows(#"Last Step" ,
each [ClientID] = _[ClientID])
, "Warehousezone")
,"Warehousezone"
)
This may create a new column that will bring the max warehousezone of a clientid everytime. At the end you can expand the record to get the value.
P/D The calculation is not so good for performance

PowerBi DAX equivalent for SUMIFS with current row value as filter

In Excel I could, if I was in a table called 'Sales' that had four columns
Sales
Month, CustomerId, ProductId, TotalQuantity
Jan,1, CAR,
Feb,1, CAR,
I could add a formula:
=SUMIFS(Sales[Quantity],Sales[CustomerId],[#[CustomerId]])
That would go to the Sales table and sum the CustomerID column filtered by the CustomerID of the current row where the formula has been entered.
I am attempted to replicate this in a PowerBI Calculated Row but I can't get the # working for a row reference. It comes across like
TotalQuantity = CALCULATE(SUM(Sales[Quantity]),Sales[CustomerId] = Sales[CustomerId]))
Any idea how to get the equivalent # working?
I think the key function you are missing is EARLIER. That is not surprising because it has a misleading name - it really means "Current Row". You also need a FILTER function in the Filter parameter of CALCULATE, to reset the filter context to the entire table.
So your New Column function might look like this:
TotalQuantity = CALCULATE(SUM(Sales[Quantity]), FILTER(Sales, Sales[CustomerId] = EARLIER (Sales[CustomerId])))
Here's a neat example, from the most accessible source site for DAX formulas:
http://www.powerpivotpro.com/2013/07/writing-a-subtotal-calc-column-aka-the-simplest-use-of-the-earlier-function/
And FWIW here is the official doco on EARLIER:
https://msdn.microsoft.com/en-us/library/ee634551.aspx

Facebook API: Getting photos that have a comment containing a a string

I'm implementing a pseudo hash-tagging system for the company I work at with their customer's facebook photos. A customer can upload a photo to the page, and a page admin can tag it with the hashtag for a product.
What I am trying to do is get all photos from the page that have a certain tag in the comments (for instance, get all photos from the company page with a comment containing only '#bluepants').
I am trying to make sure the Facebook API handles the heavy lifting (we'll cache the results), so I'd like to use FQL or the Graphs API, but I can't seem to get it working (my SQL is quite rusty after relying on an ORM for so long). I would prefer if it outputs as many results as possible, but I'm not sure if FB lets you do more than 25 at once.
This is going to be implemented in a sinatra site (I am currently playing around with the Koala gem, so bonus points if I can query using it)
Could anyone give me some guidance?
Thanks!
I've got something like this working in FQL/PHP. Here is my multiquery.
{'activity':
"SELECT post_id, created_time FROM stream WHERE source_id = PAGE_ID AND
attachment.fb_object_type = 'photo' AND created_time > 1338834720
AND comments.count > 0 LIMIT 0, 500",
'commented':
"SELECT post_id, text, fromid FROM comment WHERE post_id IN
(SELECT post_id FROM #activity) AND AND (strpos(upper(text), '#HASHTAG') >= 0",
'accepted':
"SELECT post_id, actor_id, message, attachment, place, created_time, likes
FROM stream WHERE post_id IN (SELECT post_id FROM #commented)
ORDER BY likes.count DESC",
'images':
"SELECT pid, src, src_big, src_small, src_width, src_height FROM photo
WHERE pid IN (SELECT attachment.media.photo.pid FROM #accepted)",
'users':
"SELECT name, uid, current_location, locale FROM user WHERE uid IN
(SELECT actor_id FROM #accepted)",
'pages':
"SELECT name, page_id FROM page WHERE page_id IN (SELECT actor_id FROM #accepted)",
'places':
"SELECT name, page_id, description, display_subtext, latitude, longitude
FROM place WHERE page_id IN (SELECT place FROM #accepted)"
}
To break this down:
#activity gets all stream objects created after the start date of my campaign that are photos and have a non-zero comment count. Using a LIMIT of 500 seems to return the maximum number of posts. Higher or lower values return fewer.
#commented finds the posts that have #HASHTAG in the text of one of their comments. Note, I'm not looking for a #, which is a reserved character in FQL. Using it may cause you problems.
#accepted gets the full details of the posts found in #commented.
#images gets all the details of the images in those posts. I have it on my todos to refactor this to use object_id instead of pid and try using the new real_width specification to make my layout easier.
#users and #pages get the details of the actor who originally posted the item. I now know I could have used the profile table to get this in one query.
#places gets the location details for geo-tagged posts.
You can see this in action here: http://getwellgabby.org/show-us-a-sign

Resources