I have a Firebase node structure like the following.
categories
category1
timestamps
23c491sdfwrasddgasd: true
asdf8234dfjalskdask: true
39fsdizxcasfgbskdf7: true
2asqwizxov340bs9fms: true
category2
timestamps
p23491sdfwrasddgasd: true
asdfpovaskdrfskdask: true
category3
timestamps
vmk339ffk3rasddgasd: true
asdf8234dfjalskdvml: true
bnwdwizxcasfgbskdf7: true
The timestamp keys are the keys generated by push(). I need to sort the categories by the oldest timestamp key they have. Only the oldest timestamp from the timestamps node will count.
Basically I need to sort the categories by the time they were modified for the first time.
Any help is welcome including tips to redesign the node.
have you thought about flatting your Database?
Change your Database Design to:
categories
category1
oldest_timestamp: 2asqwizxov340bs9fms
timestamps
23c491sdfwrasddgasd: true
asdf8234dfjalskdask: true
39fsdizxcasfgbskdf7: true
2asqwizxov340bs9fms: true
category2
oldest_timestamp: asdfpovaskdrfskdask
timestamps
p23491sdfwrasddgasd: true
asdfpovaskdrfskdask: true
category3
oldest_timestamp: bnwdwizxcasfgbskdf7
timestamps
vmk339ffk3rasddgasd: true
asdf8234dfjalskdvml: true
bnwdwizxcasfgbskdf7: true
Basically you have added a node called "oldest_timestamp". Now you can easily order your categories with a query.
Query myquery = FirebaseDatabase.getInstance().getReference().child("categories").orderByChild("oldest_timestamp");
Don't forget to index that in your Firebase Database Rules for better Performance.
Related
In the data I have there are multiple Boolean columns that categorise each row, for example:
Object
Fruit
Yellow
Round
Chair
FALSE
FALSE
FALSE
Banana
TRUE
TRUE
FALSE
Apple
TRUE
FALSE
TRUE
Ball
FALSE
FALSE
TRUE
I am trying to make a KPI chart that would go alongside a table of this data in which it would have 'Fruit', 'Yellow', & 'Round' as categories and a count of how many are true, so that when you click on them it will mark and limit the data in the table. In this example 'Fruit' would have a count value of 2, 'Yellow' 1, and 'Round' 2.
How can I make a single KPI chart look at multiple columns and count their True values? I tried making a second data table to unpivot the columns into rows and have their count, which works, but then I am unsure as to how to make a relation between the two table such that I can mark and limit the original data table?
Please let me know if you require any information. I am using Spotfire 10.10, and this is how the data is presented to me, I cannot change it.
I have this type of table in Power BI:
id
isPromoter
path
aaa-111-000
false
sqe-432-w14/2aq-4ec-t66/aaa-111-000/
sss-342-r34
true
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/
hhy-e90-y7u
false
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/hhy-e90-y7u/
...
...
...
So, as you can see, the second id is contained in both in the second and in the third path; this only can happen if the user is a Promoter.
I would like another field which counts how many times each id is contained in all paths (beside itself); so it should be 0 if the user is not a promoter and >0 if it is.
id
isPromoter
path
children
aaa-111-000
false
sqe-432-w14/2aq-4ec-t66/aaa-111-000/
0
sss-342-r34
true
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/
3
hhy-e90-y7u
false
a3e-543-1sd/34d-245-svt/s3a-bnj-klo/sss-342-r34/hhy-e90-y7u/
0
...
...
...
...
I know that there is the function Text.Contains([path],[id]) but it is only true for the current row. I don't know how to do the count for all rows
Add column ... custom column ... name it children, use formula
= List.Count(List.FindText(#"PriorStepNameHere"[path],[id]))-1
I'm used to writing in JavaScript so I am approaching this thinking about SWITCH statements and of course the classic if else...
I just want to check if the data in a row is TRUE, and if it is count it. If the value is not true, don't add it to the count.
I'm thinking something like this would work:
CASE
WHEN is_it_true_or_false = false
THEN COUNT_DISTINCT ( id ) //using id to address that specific row and add it to the count
END
It can be achieved by using either of the following CASE statements and aggregating the Calculated Field as required - COUNT_DISTINCT (Unique IDs of TRUE values) or COUNT (All TRUE values):
1) Where is_it_true_or_false is a Boolean OR String Field:
CASE
WHEN REGEXP_MATCH(is_it_true_or_false, "((?i)TRUE)") THEN id
ELSE NULL
END
2) Where is_it_true_or_false is a Boolean Field:
CASE
WHEN is_it_true_or_false = TRUE THEN id
ELSE NULL
END
Google Data Studio Report and GIF to elaborate:
I have the following dimensions: Patients and Collection Type (Blood or Tissue). Measure: Collections.
I am counting how many blood and tissue collections for each patient have been made.
Here is my table: Collections per Patient by Collection Type
Now I want to filter this table: I want to display only those Patients who have more then 2 Blood Collections and more then 2 Tissue Collections.
So, I want to see only Patient B, D, and E.
How can I do this?
There are a variety of ways you could accomplish your desired result. Probably one of the easier ways would be to unpivot your data such that 'blood collections' and 'tissue collections' are separate columns instead of one. I don't believe Tableau natively supports this while importing a data source currently; however, you can created two additional calculated fields to replicate an unpivot.
Blood Field:
IF [Collection_Type] = 'Blood'
THEN [Collection]
ELSE Null
END
Tissue Field:
IF [Collection_Type] = 'Tissue'
THEN [Collection]
ELSE Null
END
EDIT: Create a Calculated field that contains your desired condition for filtering, Ex.:
(SUM([Blood_field]) > 2 AND SUM([Tissue Field]) > 2)
Calculated field will evaluate to TRUE or FLASE. Filter for records for TRUE on this field
Is it possible to retrieve a count of distinct records based on a field value if the field needs to be interrogated (ideally, using ActiveRecord alone)?
For example, the following returns a count of unique records based on the 'created_at' field:
Record.count('created_at', :distinct => true)
However, is it possible to get a count of, say, unique days based on the 'created_at' field in a similar way?
A naive ActiveRecord example to explain my intent being:
Record.count('created_at'.day, :distinct => true)
(I know the string 'created_at' isn't a 'Time', but that's the sort of query I'd like to ask ActiveRecord.)
You need to group the records. For example
Record.group('DATE(created_at)').count('created_at')
tells you the number of rows created on each particular date, or
Record.group('DAYOFWEEK(created_at)').count('created_at')
would tell you the number of rows created on individual days of the week.
Beware that this with the usual active record setup this will do date calculations in UTC, if you want to do your calculations in a specific timezone you'll have to add that conversion to the group statement.