I'm trying to order search results using an equation that uses Products and User has inputs. In other words, I have an equation that uses data from both Products and current_user. I want to be able to order my search results by the number I get from the equation. I'm pretty lost on even were to begin with this. Has anyone done something similar or have any ideas of how to best handle the sort/order? From my understanding, "order" is usually used to sort actual columns in the SQL database and not a method.
I was originally thinking I would need to pass the current_user into the model. I know that's not best practice, but Sunspot allows you to create custom fields in the model and then sort on those fields. Unfortunately, this doesn't work since sunspot needs to index the fields it searches and sorts by.
I'm currently using Sunspot and would like to keep using it even if need to make modifications. I'm also using pagination.
You cannot calculate complex equations in SQL. You are restricted to simple calculations.
Possible Solutions:
Depending on how many results you get it might be possible to just
use the ruby sort method.
Calculate the result of your equation and store them in a new
column or table
Your problem could be associated with "matching".
Related
https://docs.google.com/spreadsheets/d/1wgapukUmnkgW3qZLqZ8I-FgRI1kCBw4tYGNBJnxIv_Q/edit?usp=sharing
You can see I created up and down arrows that are used to increase/decrease the percentages in column H.
It's a little bit slow because it's run by a script. Is there a faster way to do this?
You can use Data Validation for the values in your I column
The formula for your named range could be
=ArrayFormula(SEQUENCE(11,1,14,2)/100)
As for the Data Validation you can use List from a range and use my_percentages.
Using the combination of Named ranges and Data validation will give you instant results.
(Make a note that the named range can be anywhere. Even in a new tab.)
Functions used:
ArrayFormula
SEQUENCE
In QuickSight, when you want to define a constant value to reuse it in visualizations later, you can try to set it as:
Calculated field: goalFor2020
Formula: 20000
But right now it doesn't allow you to put just a number in the formula.
Is there any way to do achieve having just a number in the formula of a calculated field?
The reason we need it is just to have a number that doesn't depend on any data, just manually defined by us.
Interesting, QuickSight lets me insert a number into a calculated field, just fine.
Since that isn't working for you, I'd recommend using a parameter with a default value. For example,
Parameters essentially has the same "rights" as a calculated field (it can be used in visuals, other calculated fields, etc...). It can also be passed via query parameters which may or may not be a feature that you'd find useful.
Another cool benefit of using parameters is that, if you're embedding QuickSight, you could retrieve this value dynamically and pass it to the dashboard. Then if you wanted to, say, generalize your for different yearly goals, the goal could be passed and dynamic (rather than hard-coded in a calculated field).
We could achieve it with a trick, just apply some function that returns a number to one of your columns, and make it 0, then add your constant number:
Calculated field: goalFor2020
Formula: count(email) * 0 + 20000
It does the trick, but there might be a better way to do it.
I have tried something like this:
distinct_countIf({dimension},{dimension}='xxx')*
+distinct_countIf({dimension},{dimension}='xxx')*
just makes the discount_countif meet the requirement, so it will return to 1. And use 1* the number you want to hardcode. If the requirement does not meet, it will return 0 so it won't add up the number
I have a PowerApps gallery that lists data from 3 different tables and have it normally sorted by the following:
SortByColumns(Filter(Personnel, !Dismissed, txtMSSearchBox.Text in MemberName), "MemberName", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending))
One of the fields is displayed from the below:
Last(SortByColumns(Filter(PersonnelEvents, MemberNumber.Id = ThisItem.ID, EventType.Value="Promotion"), "Date", SortOrder.Ascending)).Title
What I would like to do is sort the gallery by this derived data. Is this even possible?
Can you try making On visible of the screen have an UpdateContext function which saves this formula as a variable.
You can then reference this variable as the column you want to sort by.
i.e something like UpdateContext({mySortColumn: Last(SortByColumns(Filter(PersonnelEvents, MemberNumber.Id = ThisItem.ID, EventType.Value="Promotion"), "Date", SortOrder.Ascending)).Title})
I just hope I really understand what you are trying to achieve, but if this doesn't work, maybe you can explain better what you are trying to do and hopefully I'll be able to help
I have decided to use Flow to update a column in my main table to show the relevant data and thereby sort by that field. I believe this would be an easier way to accomplish what I want.
Say i have something like this:
somerecord SOMETABLE%ROWTYPE;
Is it possible to access the fields of somerecord with out knowing the fields names?
Something like somerecord[i] such that the order of fields would be the same as the column order in the table?
I have seen a few examples using dynamic sql but i was wondering if there is a cleaner way of doing this.
What i am trying to do is generate/get the DML (insert query) for a specific row in my table but i havent been able to find anything on this.
If there is another way of doing this i'd be happy to use but would also be very curious in knowing how to do the former part of this question - it's more versatile.
Thanks
This doesn't exactly answer the question you asked, but might get you the result you want...
You can query the USER_TAB_COLUMNS view (or the other similar *_TAB_COLUMN views) to get information like the column name (COLUMN_NAME), position (COLUMN_ID), and data type (DATA_TYPE) on the columns in a table (or a view) that you might use to generate DML.
You would still need to use dynamic SQL to execute the generated DML (or at least generate static SQL separately).
However, this approach won't work for identifying the columns in an arbitrary query (unless you create a view of it). If you need that, you might need to resort to DBMS_SQL (or other tools).
Hope this helps.
As far as I know there is no clean way of referencing record fields by their index.
However, if you have a lot of different kinds of updates of the same table each with its own column set to update, you might want to avoid dynamic sql and look in the direction of statically populating your record with values, and then issuing update someTable set row = someTableRecord where someTable.id = someTableRecord.id;.
This approach has it's own drawbacks, like, issuing an update to every, even unchanged column, and thus creating additional redo log data, but I believe it should be considered.
The problem seems trivial, but I can't find any reasonable solution. I have list of countries with translations stored in Globalize3 translation tables. How can I fetch the list of countries sorted by name?
Country name isn't stored directly in the model, but in separate table. Is there any reasonable way to sort the result other than manual sql query, or manualy sorting result table after AR query is complete?
Country.with_translations(I18n.locale).order('name') for current locale.
Edit:
You can also use fallbacks:
Country.with_translations(I18n.fallbacks[I18n.locale]).order('name')
Country.with_translations.order('name')