PowerBI with Many to Many Relationship - many-to-many

I have two Tables in PowerBI with Many to Many Relationship, I need to find the exact count of the rows from both the tables (after adding filters) which are in same visualization table.
Image showing Relationship between tables

Related

One-to-Many relationship shared among different models

I have two different models in two different PostgreSQL tables for which there's a relationship with objects in a third table. Objects in the third table can only be linked to one object in one of the other tables (think of the two tables as pictures and posts and the other table as comments).
I only need to read from these tables, I never have to add objects in them. I have also nearly no control over the way the tables are defined.
How would I setup this relationship in SQLALchemy so that I can query posts or pictures with their associated comments ?

MS Access Multiple Many-to-Many relationships

I have one table "Liability" which is currently providing the available coverage amounts in a dropdown box. It has the following fields:
[CoverageAmountID]
[CoverageAmount]
[Cost]
[StateID]
[ProductID]
[CompanyID]
There are many coverage amounts, companies, states & products.
A complicated query currently pulls the correct Coverage Amount options. My question is if I need to split this up and how?
I have no relationships for this now but there are State, Product & Company Tables.
Do I create junction table with the CoverageAmountID, StateID, ProductID & CompanyID as the primary key?
Is there a better way to handle this with multiple m:m junction tables?
I'm struggling with how this data should be structured. The attached picture shows what I have in the table currently.
Normalizing the liability database:
Instead of using many values in one field, use intermediary tables for many to many relationships
Better use numbers for keys, using text in relationships will be challenging.
If you have one product per coverage then you have a one to many relationship in which case you can use a direct relationship from CoverageTbl to ProductTbl
Yes, you need separate tables with own primary Keys for ProductTbl, StateTbl & CompanyTbl
Attached is a tentative design showing relationships, Note all IDs are of type number, Codes are of type text(5)
database design/relationships

Multiple Tables Vs one table for e-commerce product store combination

I am running an e-commerce site with multiple stores and each store having its products. I currently have a table called product-store which has a list of all product id referencing the products name and description from a different table , prices etc and their corresponding store ids. This table could have same product repeating multiple times if multiple store carry it.
I am mooting the idea of having a separate table for each store(product-store1, product-store2) rather than having all stores in one product-store table. I could be adding 100 stores and hence 100 tables like this. The structure of each table is the same but the reason why I am thinking of doing this is for better encapsulation of data from the other stores. However this would also mean identifying the corresponding table first for the store and then fetching the data.
I need help in assessing if this is a right approach and how I can measure the two approaches.
There are very few good reasons for splitting a table into multiple tables. Here are reasons not to do it:
SQL is optimized for large tables, but not for lots of small tables with the same structure. (With small tables, you end up with lots of partially filled data pages.)
Maintenance is a nightmare. Adding a column, changing a data type, and so on has to be repeated many times.
A simple query such as "How many stores sell a single product?" are problematic.
You cannot have a foreign key relationship into this table, for instance, to have a history of prices or discounts on the product in each store.
A single table is almost always the best way to go.
I guess it also depends on if the products might be shared across different stores. I would not go the way of creating x tables for x stores, but a general structure to be able to hold all the information.
If so, you could set up at least three tables:
product (holds all the generic products information, shop independent)
store (information about the stores)
store_product (links the products to the stores)
This way you can add as many products / stores to your system without having to change database structure (which is bad anyways).
To answer some of your assumptions:
Encapsulation of data from different stores is rather selecting a subset of data that choosing different tables.
whenever you need some additional information (not being thought of in the beginning) for either stores or products, its easier to add by referencing the new table to stores/products instead of having to multiply those changes by the amount of stores.

How to compare query results for multiple tables?

I have 3 tables, User, AccessControlKey and AccessControlGroup. User can be assigned to multiple products. AccessControlKeys can be assigned to multiple AccessControlGroups. However a User cannot have AccessControlKey assigned to him more than once i.e. for a User across the multiple AccessControlGroups assigned to him, AccessControlKey has to be unique across the AccessContolGroups assigned to him.
For the many to many relationships between accesscontrolkeys and user and for many to many relationship between accesscontrolkeys and accesscontrolgroups i have two separate tables. Following is the table descriptions for the 3 tables and the relationship mapping table. How do i enforce the unique AccessControlKey across multiple AccessControlGroup for a User?
http://pastebin.com/EzL9QUGg
From your description, I'm guessing that each User has one AccessControlKey and the key can belong to multiple AccessControlGroups.
I'd probably change the data structure and change your User_BelongsTo_AccessControlGroup to a User_AccessControlKey (linking a User to an AccessControlKey) instead; you can enforce the uniqueness here. You can still get to the User's AccessControlGroups through this table and the AccessControlKey_BelongsTo_AccessControlGroup.

When or use a many-to-many relation in a database?

I want to know in what situations we create many to many relation. What is the need of doing such?
A quick search goes a long way. Though the following is for MS Access, the concept is the same for any relational database.
Via: office.microsoft.com - Create a many-to-many relationship:
You have a many-to-many relationship when a single record in one table
can relate to many records in another, and a single record in that
second table can also relate to many records in the first. For
example, say your company has several types of computers and several
technicians, with each technician certified to work on some, but not
all, of the computers. Each technician can be related to more than one
computer, and in turn, each computer can be related to more than one
technician.
To track who can work on a given machine, you create a many-to-many
relationship by adding the primary keys from both sides of the
relationship to a third table, called a junction or link table. In
other words, a many-to-many relationship is really just a pair of
one-to-many relationships.