Power BI distinct users for distinct applications - powerbi

my table is like given below
APP NAME  USER ID
APP_A        P1001
APP_A        P1002
APP_A        P1003
APP_A        P1004
APP_B        P1001
APP_B        P1002
APP_B        P1003
APP_C        P1001
APP_C        P1002
APP_C        P1004
APP_D        P1001
APP_D        P1002
APP_D        P1004
APP_D        P1005
need result like, common users from all applications
Sample result
APP NAME   USER ID
APP_A         P1001
APP_A         P1002
APP_B         P1001
APP_B         P1002
APP_C         P1001
APP_C         P1002
APP_D         P1001
APP_D         P1002
SUMMARIZE function did not help

Got solution, working now. Thanks.
https://community.powerbi.com/t5/Desktop/distinct-users-for-distinct-applications/m-p/3052227/thread-id/1037538#M1037565

I don't understand actually what is your question but you have to transform your data and on the transform data tab you can check the value of columns and get the desired result.

Related

Concatenate rows based on user selection

I have a table like this:
Ticket Number
Client
Type
T123
Andy
Question
T456
Bob
Issue
T789
Charlie
Problem
I use the filters to display which tickets I am interested in, then open Excel and use
= "www.myticket.url/" & TEXTJOIN("&",TRUE,A:A)
in order to open the url to display all my tickets (in this case, www.myticket.url/T123&T456&T789)
Is there a way to display this dynamically created URL directly in Power BI rather than having to download to Excel?
You can create a measure using CONCATENATEX DAX function to concatenate the values in Ticket Number column, with & separator.
The measure could look like this (where Table is the name of the table):
URL = "http://www.myticket.url/" & CONCATENATEX('Table', [Ticket Number], "&")
Probably you will also want to set the data category of the measure to Web URL.

bulk insert data with Postgres into QuestDB

How does one bulk insert data with Postgres into QuestDB?
The following does not work
CREATE TABLE IF NOT EXISTS employees (employee_id INT, last_name STRING,first_name STRING);
INSERT INTO employees
(employee_id, last_name, first_name)
VALUES
(10, 'Anderson', 'Sarah'),(11, 'Johnson', 'Dale');
For inserting data in bulk, there are a few options. You can use CREATE AS SELECT to bulk insert from an existing table which is closest to your example:
CREATE TABLE employees
AS (SELECT employee_id, last_name, first_name FROM existing_table)
Or you can use prepared statements, there are full working examples in a few languages in the QuestDB Postgres documentation, here is a snippet from the Python example:
# insert 10 records
for x in range(10):
cursor.execute("""
INSERT INTO example_table
VALUES (%s, %s, %s);
""", (dt.datetime.utcnow(), "python example", x))
# commit records
connection.commit()
Or you can bulk import from CSV, i.e.:
curl -F data=#data.csv http://localhost:9000/imp

Django How to select differrnt table based on input?

I have searched for the solution to this problem for a long time, but I haven't got the appropriate method.
Basically All I have is tons of tables, and I want to query value from different tables using raw SQL.
In Django, we need a class representing a table to perform the query, for example:
Routes.objects.raw("SELECT * FROM routes")
In this way, I can only query a table, but what if I want to query different tables based on the user's input?
I'm new to Django, back in ASP.NET we can simply do the following query:
string query = "SELECT * FROM " + county + " ;";
var bus = _context.Database.SqlQuery<keelung>(query).ToList();
Is this case, I can do the query directly on the database instead of the model class, and I can select the table based on the user's selection.
Is there any method to achieve this with Django?
You can run raw queries in Django like this -
From django.db import connection
cursor = connection.cursor()
table = my_table;
cursor.execute("Select * from " + table)
data = cursor.fetchall()

Hele converting MSSQL query to Korma entities

I have the below MSSQL query for which I am not able to figure out the Korma entities. Please help out
select t.d as did from (
select dataid as d , count(dataid) as
cd from <table_name>
WHERE prid = <pid> group by dataid
) as t WHERE t.cd >1;
Thanks
SQL Korma documentation site contains subselect sample:
;; Subselects can be used as entities too!
(defentity subselect-example
(table (subselect users
(where {:active true}))
:activeUsers))

postgresql full text search query to django ORM

I was following the documentation on FullTextSearch in postgresql. I've created a tsvector column and added the information i needed, and finally i've created an index.
Now, to do the search i have to execute a query like this
SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank
FROM client, plainto_tsquery('famille age') query
WHERE textsearchable_index_col ## query
ORDER BY rank DESC LIMIT 10;
I want to be able to execute this with Django's ORM so i could get the objects. (A little question here: do i need to add the tsvector column to my model?)
My guess is that i should use extra() to change the "where" and "tables" in the queryset
Maybe if i change the query to this, it would be easier:
SELECT * FROM client
WHERE plainto_tsquery('famille age') ## textsearchable_index_col
ORDER BY ts_rank_cd(textsearchable_index_col, plainto_tsquery(text_search)) DESC LIMIT 10
so id' have to do something like:
Client.objects.???.extra(where=[???])
Thxs for your help :)
Another thing, i'm using Django 1.1
Caveat: I'm writing this on a wobbly train, with a headcold, but this should do the trick:
where_statement = """plainto_tsquery('%s') ## textsearchable_index_col
ORDER BY ts_rank_cd(textsearchable_index_col,
plainto_tsquery(%s))
DESC LIMIT 10"""
qs = Client.objects.extra(where=[where_statement],
params=['famille age', 'famille age'])
If you were on Django 1.2 you could just call:
Client.objects.raw("""
SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank
FROM client, plainto_tsquery('famille age') query
WHERE textsearchable_index_col ## query
ORDER BY rank DESC LIMIT 10;""")