I'm trying to make a measure that needs two "many to many" relationships between the same tables to work.
Is this possible ? i'm trying to make it work but it seems that the PowerBi program doesn't permit this from happening.
It's a name column and a date column. i use filters based on this two columns but it only permits one relation. So, if i create a date relation the name filter doesn't work and vice versa.
Someone knows another way around it ?
The data is sensitive so i can't post it, but if needed i can try to make a fake one that shares its characteristics.
Related
I would like two measures that SUM the Sales[Value] for all the Sales[ID] that have a specific StatusID in SalesStatus.
One that can filter on Sales[Date], and one that can filter on SalesStatus[statusDate]
Diagram
Regards,
Anders
In this scenario I would consider modifying your model to have only two tables by combining what appears to be two FACT tables (sales, sales status). Depending on what your data consists of I would either UNION the two tables after joining and then treat the date in your Sales table as another status date (i.e. shipped complete or sale finished, whatever that date represents) OR I would join the two tables and have two relationships to the date table.
This will create a duplicated data issue as you will ideally result in having the value column in your final fact table. If you go with the union option, you can force the user to select a single sales status effectively removing the sales duplication. If you end up with two connections to the date table, you can use the USERELATIONSHIP() function to write the two different sales measures, and the one that uses the date from the Sales table will need some clever tricks to ensure the data does measure does not duplicate. I would try to UNION the tables though.
For more details, I would research what's referred to as SEMI-ADDITIVE fact tables in datawarehousing. There is a great article from SQL BI on the subject. I have tried setting up models like you diagrammed and even if I could get them to work through intense DAX measures, they would produce unexpected results and have poor performance. I find the Semi additive fact table pattern to be a much cleaner solution once you get passed the data duplication that results.
Example:
I have a data model in Power BI that, among other things, has the following tables
Employees (Dimension; employee ID/name)
Jobs (Dimension; contains details about the job, including job ID)
Employee history- Contains a record for each day an associate was in a job(snapshot table);
Job Budget History- Contains a record for each day a job was budgeted(snapshot table)
Calendar Table
The table is modeled like so (simplified version):
In Power BI, I am trying to make a simplified table view that contains measures based on both the budget history as well as the employee history for the most recent day in the dataset (simple count rows/distinct count of calendar table)
However, attempting to do so gives me the results below if I try to put both measures on the table. Basically it appears to be doing a cross join between each table and matching associates with jobs they don't have (this happens when the budget is added).
Of course, if I just do one of the singular measures everything works perfectly. I am fairly certain it is because there is no real connection between the 'employee' and the 'budget history' in this relationship, so it is just joining everything on the date without any context.
I have tried several things such as making inactive relationships with userelationship(), using visual level filters etc. but I'm not sure what the best option in this situation would be. (I am trying to avoid bidirectional relationships if possible)
Ideally this information should show on this date that Joe was present as President, Sally was present as an operator, and the Manager position had nobody, but all three were budgeted.
Any advice is appreciated. I have attached a simplified mockup pbix file for reference.
PBIX File
This is a complicated problem for many reasons. I was able to produce this report:
by removing field "Name" from the table and replacing it a measure:
Employee Name =
CALCULATE(
SELECTEDVALUE(Employees[Name]),
CROSSFILTER(Employees[Employee_ID], Employee_History[Employee_ID], BOTH)
)
It looks exactly like the report you want, but if you have additional requirements, you'll need to make sure that such approach works for you.
If this is acceptable, a brief explanation:
the root cause of the issue is missing Employee-Budget relationship. When you put Name in the table as a filter, it doesn't propagate to the budget table and causes a cartesian product.
Removing Name from the table eliminates the need for the filter propagation, but then you won't see employee names. I solved this by pulling employee names with the measure, where required propagation is forced by CROSSFILTER function (essentially, it's like a temporary bi-directional relation only when you need it, so it does not negatively affect the rest of the model).
In my table primary key column have missing value, i have tried to fill using measure but it is not work because not full fill the primary key val of column to measure
For handling missing values, you need to follow the following two steps:
Replace the missing values with the desired values in Query Editor in Power BI Desktop (optional)
Remove the bi-directional relationships and create uni-directional relationships among tables
Note: The direction of the relationship plays a very important role in modeling in Power BI. The direction of the relationship means the way that filter propagates in Power BI. The uni-directional relationship will filter one table based on the other one. Sometimes you need to filter in a different direction, that is when the bi-directional relationship comes into play. However, bidirectional relationship comes with a cost of performance issues. Do not use bi-directional relationships blindly. Make sure you have designed your model in the right way first, and if that doesn’t work, then try other methods such as Cross-Filter DAX functions.
I have created static table as blow and create relationship with original tables then assigned value static table column on visual table which is working with out any issue
Create Static stable:
create relationship
assign column to visual table and filter result column should not be empty
I have a table of dates (every date from 2003 to 2035) in my data model but am wondering if I need to create relationship(s) between this and my other data tables, wondered if anyone could please share best practice?
If so, my main table has several columns of dates so which would I link to?
To be honest, I am thinking I shouldn't create a relationship as any filtering of the date table will then only filter my model by which date column I have a relationship with?
I hope all that makes sense. It's more of an abstract question at the moment but my ultimate goal is to create some kind of rolling average.
Thanks in advance.
The best practise is clearly to create a relationship between your date table and your data table (fact table I assume). But you have to choose the most relevant column to make your link, knowing that it's preferred to not make multiple relationships between the same tables.
If you have a "snapshot date" column, you could make the link with this one to see the status for that period for example. It really is up to you.
If the filtering is annoying to you, you can always disable it on the visuals.
I hope it helps.
I'm attempting to create a shared date dimensions between two fact tables in Power BI, based off of a relational data source.
Currently, if I include an unrelated dimension in the report, I get numbers duplicated across multiple rows, where they don't really apply.
I'm wondering if there is any way to tell Power BI that certain dimensions cannot be used with certain fact tables, similar to using IgnoreUnrelatedDimensions in SSAS.
Currently the only solution I can find is to create a separate date dimension, so that the two fact tables have no relationship that could be used to join them, however this would mean forfeiting the ability to do any time based comparisons.
Create a combined view of the fact tables with only compatible columns to be used for time based comparison:
In Query Editor, create new queries for your fact tables by
referencing i.e. right click original query and select "Reference".
Then in those "copies" cut out the incompatible dimensions.
Rename columns to align terminology (e.g. Sales Date ==> Transaction Date, Payment Date ==> Transaction Date).
Use "Merge Queries" function to combine the copies using Full Outer Join.
Join this merged view to your date dimension