I want all users which are not members of my User table to see everyones data - ssas

I have a table with Sales Teams (DimSalgsTeams) and another one with all salelsmen for all teams (DimSaelgere), and only a users (salesmen) from the same Team can see each others rows.
My model works great, but the issue is that all other members of specified AD Group should see everything.
How can I achive that in this model?

I changed the code in DAX filter to:
=IF(CONTAINS(DimBrugerRettigheder, [original_login], USERNAME()), DimBrugerRettigheder[original_login] = USERNAME(), TRUE())
And it solved my problem.

Related

Counting the number of times a result from a query shows up (basic SQL question)

I have these three tables:
I need to list staff names and the number of projects they have worked on, I'm not really sure how to do this. Right now I'm able to list all the staff members who have worked on a project using this:
SELECT staff.s_name FROM Staff staff
INNER JOIN Work_on work ON staff.s_id = work.s_id
INNER JOIN Projects proj ON work.p_id = proj.p_id
And this displays the names of all the people who have worked on a project, some names are listed twice, indicating how many projects they've worked on. I don't know how to list this as a separate value though and display both their names and the number of projects they've been working on, obviously I'd need to use the COUNT() function somewhere but I don't know how to count everytime a name appears from the result. Could someone provide me a tip of sorts?
The result is supposed to look like this:
Right now I'm only getting this:
Which is correctly displaying how many times a user has worked on a project, but I don't know how to use this to create another column displaying the count.
Would it help?
SELECT staff.s_name, count(1) FROM Staff staff
JOIN Work_on work ON staff.s_id = work.s_id
GROUP BY staff.s_name

Tableau count values after a GROUP BY in SQL

I'm using Tableau to show some schools data.
My data structure gives a table that has all de school classes in the country. The thing is I need to count, for example, how many schools has Primary and Preschool (both).
A simplified version of my table should look like this:
In that table, if I want to know the number needed in the example, the result should be 1, because in only one school exists both Primary and Preschool.
I want to have a multiple filter in Tableau that gives me that information.
I was thinking in the SQL query that should be made and it needs a GROUP BY statement. An example of the consult is here in a fiddle: Database example query
In the SQL query I group by id all the schools that meet either one of the conditions inside de IN(...) and then count how many of them meet both (c=2).
Is there a way to do something like this in Tableau? Either using groups or sets, using advanced filters or programming a RAW SQL calculated fiel?
Thanks!
Dubafek
PS: I add a link to my question in Tableu's forum because you can download my testing workbook there: Tableu's forum question
I've solved the issue using LODs (specifically INCLUDE and EXCLUDE statements).
I created two calculated fields having the aggregation I needed:
Then I made a calculated field that leaves only the School IDs that matches the number of types they have (according with the filtering) with the number of types selected in the multiple filter (both of the fields shown above):
Finally, I used COUNTD([Condition]) to display the amounts of schools matching with at least the School types selected.
Hope this helps someone with similar issue.
PS: If someone wants the Workbook with the solution I've uploaded it in an answer in the Tableau Forum

Active Record where join table record doesn't exist

I am trying to get a list of all records that don't exist in a join table.
The models are User, Game and MarkedGame, where users can mark games as played. It's a many to many relationship:
User > MarkedGame < Game
What I want is a list of all games that haven't been marked by the user.
I know that I could do two separate queries and subtract them:
Game.all - current_user.games
But I don't like that this leaves me with an array rather than an Active Record relation object. Plus it seems like there should be a more performant way of doing it.
If there is no Active Record way of handling this, is there perhaps a SQL way? My raw SQL is not particularly strong so any help on that would be appreciated.
Thanks.
You can try the following:
Game.where.not(id: MarkedGame.where(user_id: current_user.id).pluck(:game_id))
That should do it. Returns all games that have not been marked by the current user.
Game.where('id not in (select game_id from marked_games where user_id = ?)', current_user.id)

How to get users who belong to a WordPress Multisite blog (site) with SQL?

I need to get all the users who have joined (are members) of a site (blog) in WordPress multisite.
To complicate it, I am doing this outside of WordPress and don't have access to internal Wordpress functions, so need to construct the SQL directly.
In English the SQL would break down as "get an array of user IDs of users that are members of site x" (where site relates to one of the WordPress Multisite sites).
I've tried going through WordPress code to understand, but struggling with the above.
I don't need the PHP, I can work that out, just an example SQL statement.
Many thanks!
select * from wp_blogs
From the output of the command note down the blog_id you want the users of. For eg: say you are wanting the users of the site with blog_id = 2 , next run the following query.
select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities"
Thanks for this code, just what I needed!
If it helps anyone else, I also extended it a bit to get how many people have a given role, e.g. a custom role teacher was used below:
select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities" AND um.meta_value LIKE '%teacher%'
This of course requires other roles not to contain the word teacher (e.g. maybe there's a role ex-teacher which it would also pick up). That was the case for me so I ran two queries and subtracted the two numbers.
If anyone knows how to do it with one query that would be nice?

ldap query for group members

I'm trying to make an LDAP query, to get a list from all my groups/members. I can't figure out how can i do this. All my tries were unsuccesfull.
My "AD tree": mydomain.local/Mybusiness/Distribution Groups/ here are my groups
I tried with somethin' like this:
(objectCategory=user)
(memberOf=CN=Distribution Groups,OU=Mybusiness,DC=mydomain.local,DC=com)
I appreciate if somebody could help me to write an ldap query, which gives a list with my groups and the members of this groups.
The query should be:
(&(objectCategory=user)(memberOf=CN=Distribution Groups,OU=Mybusiness,DC=mydomain.local,DC=com))
You missed & and ()
Active Directory does not store the group membership on user objects. It only stores the Member list on the group. The tools show the group membership on user objects by doing queries for it.
How about:
(&(objectClass=group)(member=cn=my,ou=full,dc=domain))
(You forgot the (& ) bit in your example in the question as well).
The good way to get all the members from a group is to, make the DN of the group as the searchDN and pass the "member" as attribute to get in the search function. All of the members of the group can now be found by going through the attribute values returned by the search.
The filter can be made generic like (objectclass=*).