Quicksight User Entered Variables - amazon-web-services

Is it possible for Quicksight to allow user entered strings as variables for a calculated field?
For example if i have the user enter value x in a filter list (or elsewhere), can I have Quicksight save that variable x so i can create a calculated field such as:
ifelse('item' = x, 1,0)?

You can create calculated fields with parameters. I let you here an example:
Example

Related

Django Dynamically Calculate Average

I've multiple fields in my model, and I need to remove the average of only the columns user inputs
Could be
How can I do it dynamically?
I know I can do
mean = results.aggregate(Avg("student_score"))
This is one, I want to add multiple Avg statements dynamically
I tried making a loop as well to get all names and add all fields given by user one by one
eg - Avg('students'), Avg('playtime'), Avg('grade'), Avg('sales')
But I get
QuerySet.aggregate() received non-expression(s): <class 'django.db.models.aggregates.Avg'>('students'), <class 'django.db.models.aggregates.Avg'>('sales').
I've even tried raw query, but it needs a unique ID because of which that isn't working
Any workaround ideas?
I am using MySQL DB
Aggregate return single result from the list of objects. You need to annotate if you need multiple result like following,
YourModel.objects.values("YOUR GROUP BY VALUES HERE").annotate(Avg('students'), Avg('playtime'), Avg('grade'), Avg('sales')

django setting filter field with a variable

I show a model of sales that can be aggregated by different fields through a form. Products, clients, categories, etc.
view_by_choice = filter_opts.cleaned_data["view_by_choice"]
sales = sales.values(view_by_choice).annotate(........).order_by(......)
In the same form I have a string input where the user can filter the results. By "product code" for example.
input_code = filter_opts.cleaned_data["filter_code"]
sales = sales.filter(prod_code__icontains=input_code)
What I want to do is filter the queryset "sales" by the input_code, defining the field dynamically from the view_by_choice variable.
Something like:
sales = sales.filter(VARIABLE__icontains=input_code)
Is it possible to do this? Thanks in advance.
You can make use of dictionary unpacking [PEP-448] here:
sales = sales.filter(
**{'{}__icontains'.format(view_by_choice): input_code}
)
Given that view_by_choice for example contains 'foo', we thus first make a dictionary { 'foo__icontains': input_code }, and then we unpack that as named parameter with the two consecutive asterisks (**).
That being said, I strongly advice you to do some validation on the view_by_choice: ensure that the number of valid options is limited. Otherwise a user might inject malicious field names, lookups, etc. to exploit data from your database that should remain hidden.
For example if you model has a ForeignKey named owner to the User model, he/she could use owner__email, and thus start trying to find out what emails are in the database by generating a large number of queries and each time looking what values that query returned.

Using USERNAME as part of a condition in Power BI

Let's suppose I've got a simple table with two columns: user, value
Is it possible to use the function USERNAME within a code in order to filter the information that corresponds only to the user that is logged? Something like this:
Select username, value
from table
where username = USERNAME()
And show only the information that every user should see.
Regards
Yes, it's possible. You can use the USERNAME or USERPRINCIPALNAME as a filter in CALCULATE or as part of a Row Level Security filter.

Django Session - set two related data into one session variable

I have these following two data which I want to save into session, so that I can call all of them in last-preview page:
1) product title, 2) product size
I am wondering how to save this into session. My problems are: Session keys are unique so I cannot name the session name with some name. another issue is that these 2 data are coming dynamically. So I cannot use the product title as session key.
I want that both data is saved in one session variable.
Session variables are simply stored as the json-serialization of the actual value. This means that you can use lists, tuples and dictionaries, and any other json-serializable values.
One solution is to store your products as a list of (name, size) tuples. Then you can do:
if request.session['products']:
request.session['products'].append(('name', size))
else:
request.session['products'] = [('name', size)]

SharePoint calculated columns

Can I create a calculated column that totals the record count in another list based on a field value?
Example:
List1 contains departments, each with a deptID
List2 contains employees, each assigned to a deptID
Can List1 contain a total employee count (for that deptID)?
No, this field does not exist.
You can create custom view or workflow (or maybe eventreciever) on add item in the list2, which will change corresponding field of conformity item in the list1.
But it's best just to create the custom view.
No, calculated field can refer only to fields in the same item.
I suggest you to use EventReceiver to accomplish your request. Register the receiver to the employee list with ItemAdded, ItemUpdated and ItemDeleting events. In the receiver's methods update corresponding department item and its field (number of employees).