From a one to many SQL dataset Can I return a comma delimited list in SSRS? - list

I am returning a SQL dataset in SSRS (Microsoft SQL Server Reporting Services) with a one to many relationship like this:
ID REV Event
6117 B FTG-06a
6117 B FTG-06a PMT
6117 B GTI-04b
6124 A GBI-40
6124 A GTI-04b
6124 A GTD-04c
6136 M GBI-40
6141 C GBI-40
I would like to display it as a comma-delimited field in the last column [Event] like so:
ID REV Event
6117 B FTG-06a,FTG-06a PMT,GTI-04b
6124 A GBI-40, GTI-04b, GTD-04c
6136 M GBI-40
6141 C GBI-40
Is there a way to do this on the SSRS side of things?

You want to concat on the SQL side not on the SSRS side, that way you can combine these results in a stored procedure say, and then send it to the reporting layer.
Remember databases are there to work with the data. The report should just be used for the presentation layer, so there is no need to tire yourself with trying to get a function to parse this data out.
Best thing to do is do this at the sproc level and push the data from the sproc to the report.
Based on your edit this is how you would do it:
To concat fields take a look at COALESCE.
You will then get a string concat of all the values you have listed.
Here's an example:
use Northwind
declare #CategoryList varchar(1000)
select #CategoryList = coalesce(#CategoryList + ‘, ‘, ”) + CategoryName from Categories
select ‘Results = ‘ + #CategoryList
Now because you have an additional field namely the ID value, you cannot just add on values to the query, you will need to use a CURSOR with this otherwise you will get a notorious error about including additional fields to a calculated query.
Take a look here for more help, make sure you look at the comment at the bottom specifically posted by an 'Alberto' he has a similiar issue as you do and you should be able to figure it out using his comment.

Related

How to pass parameter to my POWERBI embedded report?

I have an IFrame which shows a PowerBI embedded Report that shows a list of Accounts.
I want to pass in an Account ID so that I only see the sales for my Account.
In side the report I have a Table lets say in called Query1 and Inside that table I have a field called AccountID. I need to add to my URL to filter the Accountid = 123.
My URL is something like this....
https://app.powerbi.com/reportEmbed?reportId=xxxxxxxxxxxx&autoAuth=true&ctid=xxxxxxxxxxx-xxxxxxxxx&config=eyJjbHVzdGVyVXJsIjoiaHR0cHM6Ly93YWJpLXdlc3QtZXVyb3BlLXJlZGlyZWN0LmFuYWx5c2lzLndpbmRvd3MubmV0LyJ9
What exactly should I add to filter the report by the AccountID?
You should add url parameter called filter. You need to specify table and field you want to filter and add value of the filter after eq. So your end result should be something like that:
URL?filter=Table/Accountid eq 123.
Here's Microsoft documentation about it https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-url-filters#query-string-parameter-syntax-for-filtering
Update top part of course works for filtering reports in the appor work space itself. To filter embedded report you need to specify the page and filter in a similar fashion for the embedded link https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-embed-secure. So you link will be something like that:
https://app.powerbi.com/reportEmbed?blabla&pageName=Page1&$filter=Table/Accountid eq 123
Here how it would like once embedded:

Filtering by keyword (string) in PowerBI

I have a data visualization in PowerBI that is powered by SQL on the back-end. I have one particular field that I'd like to be able to filter by string-matching. Here's what the field looks like:
me_drug_occurence
AB
C
ABC
BC
B
Each letter is unique and stands for a type of drug. More letters = combinations of drugs. No letter repeats more than once for a record. I want to use the "Filters on the page" option and have the user be able to filter by drug A, B, and C. By selecting A, for example, that would show any record that contains A (records AB, ABC,). Selecting A and B would show any record which contains A OR B (records AB, ABC, BC, B). And so on and so forth.
My issue is that there doesn't seem to be an out-of-the-box way to do this in Power BI? If I simply drag this column to the "filters on this page" sidebar, I just get options to filter by the different drug combinations.
If I choose "advanced filter", I can get closer to my goal, but it forces the user to put the keywords in manually:
So, my question is how can I accomplish a filter on this visualization that would look something like this:
Filter:
A
B
C
Where you could filter by any record that contained A, B, or C, or some combination thereof. Do I need to create a custom measure?
You already are on right path.
Use Advanced filtering.
In this use OR condition
I.e
drug contains C or drug contains B or drug contains A
This will filter out your records with only those which have either of above 3 condition matched.
Edit:
This is closest I could come up with your req.
1 Use slicer, for this slicer add filed drug occurence make it dropdown and searchable.
Now as a end user I will type in A so i get N no of records which will contain A.
As I user I will select all those records as screenshot below
and then If I type C it will show as below and select them as well
This will be the result
Now there is one filter on market place called Text Filter. Import it from marketpalce and there you can search like text (contains) but there you cannot add three different conditions. It will look something like below
Without text filter
After adding text for filter

Python + MySQL DB dynamic insert query based on number of columns to insert

I'm pretty novice at programming (recently learned functions), and have found myself re-writing the same "insert into mysql table" function (below) from script to script... mainly to just modify these two section - (name,insert_ts) &&& VALUES (%s, %s)
Is there a good way to re-write the below to accept ANY number of values , based on length of a tuple that contains values as well as inserting the column headers based on 'labels' list? VALUES (%s, %s) and this part (name,insert_ts)
list_of_tuples = [] #list of records to be inserted.
#take a list of dictionaries - and create a list of tuples in proper format/order
for dict1 in output:
one_list = []
one_list.extend((dict1['name'],dict1['insert_ts']))
list_of_tuples.append(tuple(one_list))
labels = ['name', 'insert_ts']
#db_write accepts table name as str, labels as str, and output as list of tuples
def db_write(table,labels,output):
local_cursor.executemany(""" INSERT INTO my_table
(name,insert_ts) #this is pulled from 'labels'
VALUES (%s, %s) #number of %s comes from len(labels)
"""
, list_of_tuples)
local_db.commit()
local_db.close()
#print 'done posting!'
Or, is there a better way to accomplish what I'm trying to do, using mysqldb?
Thank you all in advance!
After a bit of experience (3 months, heh), wanted to update everyone on the solution that seems to work pretty well!
Instead of using mysqldb, I spent some time learning how to use SQL Alchemy python package, and would recommend everyone do the same!
SQL Alchemy allows you to:
1) Define a table within python code (used Excel to come up with column names, etc).
2) Most important! You can pass on a dictionary to SQL Alchemy, and as long as dictionary's key names match the table's key names, everything will magically get posted to your SQL table. If you have 60 columns in your sql table, but your dict has only two keys - BAM, SQL Alchemy will take care of everything and post just the two values, and leave the other values in MySQL as blanks. MAGIC!

Using list manager in Oracle Apex 5

Am building an application with oracle apex 5 where i want the user to chose multiple parameters and returning an interactive report based on the parameters selected by the user.
One of the parameters is a list manager item where the user select multiple values to be passed to an SQL query.
my problem is how to pass those values to the sql query, the item type is list manager and the name is P2_OPTIONS how do i pass the parameters to the SQL query generating the report.
Selected values storing in P2_OPTIONS divided by colon, for example 2:7:17.
So, you can insert this string into your query, preliminary replacing colon to comma and get expression like
...
and parameter0 in (2,7,17)
...
OR
you can parse this string into apex collection and join this collection in you query
...and apex_collections.collection_name = 'P2_OPTIONS_PARSED'
and parameter0 = apex_collections.c001
...

How to phrase sql query when selecting second table based on information on first table

I have two tables I would like to call, but I am not sure if it is possible to combine them into one query or I have to some how call 2 different queries.
Basically I have 2 tables:
1) item_table: name/id etc. + category ID
2) category_table: categoryID, categoryName, categoryParentID.
The parent categories are also inside the same table with their own name.
I would like to call on my details from item_table, as well as getting the name of the category, as well as the NAME of the parent category.
I know how to get the item_table data, plus the categoryName through an INNER JOIN. But can I use the same query to get the categoryParent's name?
If not, what would be the mist efficient way to do it? The rest of the code is in C++.
SELECT item_table.item_name, c1.name AS CatName, c2.name AS ParentCatName
FROM item_table join category_table c1 on item_table.categoryID=c1.categoryID
LEFT OUTER JOIN category_table c2 ON c2.categoryID = c1.categoryParentID
SQL Fiddle: here