I am a beginner in Power BI. Just started working on DAX. I have a question regarding relationship.
I have made four tables i.e. Sales, Products, Product Category, Product Sub Category. Found that relatable columns are automatically picked up. ProductKey column in Product table contains unique Product Key and that propagates Sales Table where Product Key gets repeated. The arrow direction is from Products table to Sales table. '1' is added to Products and a '*' is added to Sales. I think this type of relationship is called 'One to Many' but when I check the properties of the relationship it indicates as 'Many to one'. If tried to change to 'One to Many' it shows error statement. Please help me out of this problem. Thanks.
Since you are saying that Product table has '1', while the Sales table has '*', so this is a One-to-Many relationship. However, when you open the relationship properties then you see the 'cardinality' as 'Many to one'. That is only because in the 'Edit relationship' window your table selection sequence is opposite. That is, the Sales table is selected at the top and the Product table is showing in the bottom.
So, summary, the relationship is correct, nothing to be worried about. :)
Rehan
There is no need to worry about your design however I will suggest you merge "Product Category" with "Product SubCategory" tables so you can achieve a star schema which works best with PowerBI.
Related
I am creating free accounting package in libreoffice-base to compete already available ones your contribution is appreciated. the package include tables:
items
item_groups
order_details
sales_bill_desc
cash
units
companyinfo
bill sales
Customer_ledger
etc.
and created two forms
first to enter items in items table with following fields:
id
List item
particulars
units from units table linked with id gst chooses from
tax table related as id basic price basic stock, barcode, group,
subgroup,
second form is sales bill entry form
it contains a form which relates to order_details table selects customers name from ledger where its state code is also defined e.g. for punjab its 03 basically it is picked from customer's GSTIN number
a subform which is connected to sales_bill_desc table related to order_details table with bill number in both tables.
now in subform when we enter one item, its name is displayed which is same entered in sales_desc table additionally it also need automatically display item units, gst, price(editable field but basic price must be displayed there).but it does not. how to do that i have studied books but am lacking i created same in access 2016 somewhere which worked fine (full working package accounts with inventory).At this time,I am trying to use same database but advanced with features such as barcode. Of course the issue is to be resolved if someone can help. I am loading code of the package.Please rectify and update.
I have a table customers with the fields id, name and so on.
One table doctors with the fields id, name.
Then there is one table subject_areas which has all subject areas which a doctor can have. The fields are id, text.
So, each doctor can have multiple subject areas. There is one pivot table doctor_subject which is a belongsToMany relation.
Here is my problem: A customer can have multiple doctors, but only for a specific subject area. I tried it with a new table customer_doctor with the fields id, customer_id and doctor_subject_id. But how do i map this in Eloquent?
Issue was in relation between tables. After chat clarification this came out as solution:
Html form is written in a way that customer first choose doctor, then depending on selection choose several of his available areas.
In that scenario customer needn't to be related to areas directly and should be related to areas only over relation with doctor.
Also as side note, if needed deeper relations, models on pivot tables could be created and used as well.
I have looked for an answer here among other places but havent quite been able to find what I need to know.
I have 3 tables, Order_Details, Products_Ordered and Product_Details. The first two are being used in a master detail form to show the order and the items ordered together. The Products_Ordered table has a composite primary key made from two foreign keys, the first being the primary key from the Order_Details table, and the second being the primary key from the Product_Details table. Together they ensure that a type of product can only be added to an order once. If someone wants to order more than one product then the quantity field in the record can be altered to reflect this. All that seems fine so far.
My issue is that when adding products to the order in the master detail form i have used a drop down list of values to select the product to add to the order. the display value for this is the product name and the return value for it is the primary key for the product from the Product_Details table.
I like this because its easier for the user to simply select the product and add a quantity of it to the table. And it works fine for both insert and update operations apart from one situation.
If the user selects the same product in to rows then submits the table the database then tries to add the product to the order twice, throwing a "ORA-00001: unique constraint violated." error. Obviously this is because of the product ID being used in the primary key of the table.
I don't want to allow the user to add two records to the table like that, rather id like to force them to alter the quantity field accordingly. The error message that comes up isn't very user friendly so my question is how can I detect this error and display a more user friendly one instead telling them to alter the quantity field instead?
*If this isn't possible then is there a way that I can hide any already selected products from the dropdown list of values in the following table rows? I haven't looked into this too much because surely it would get complicated when the user tries to add more rows than products available in the dropdown and there are no more products values to show?
I am quite new to this so please be nice. Any help is greatly appreciated :D
Here is a link where all is nicely described:
https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm
Section
Predefined PL/SQL Exceptions
in combination with:
Defining Your Own PL/SQL Exceptions
and
Defining Your Own Error Messages: Procedure RAISE_APPLICATION_ERROR
Hope it helps...
I've two tables user and product, along with their relationship user_product. The relationship table contains an extra field category. Now I want to find
the number of products selected by a user of a particular category.
I've done it in my page through coding. Is there any easier way to do this?
How to use field of pivot table?
you can use withPivot
Ex:
$this->belongsToMany('Role')->withPivot('foo', 'bar');
I'm using ActiveRecord inside CodeIgniter to interact with a MySQL database.
I have a product table and a product_photo table that stores associated photos for products along with a sort_order for each product_photo.
I am attempting to select the first product photo (lowest sort_order) but can't seem to make it work.
I've boiled it down to selecting the product_photo and joining the product to it (I tried the opposite initially) but I always end up with the first product_photo for the first test product and second product_photo for the second test product.
To simplify further, I tried selecting just the product_photo records, sorting them by product_id and sort_order, and then spitting that out and I still end up with mis-matched results.
Here's my ActiveRecord query:
$this->db->select('product_id, url, sort_order')
->from('product_photo')
->order_by('product_id, sort_order')
->group_by('product_id');
I'm sure there is a better approach to this, but I haven't found it yet. Thanks in advance for any insight.
Can't you use DISTINCT 1? Also, you should be selecting from the product table, and Use a left join to select the corresponding photo.