Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi all, I'm new to Power BI and I'm trying to create a measure with multiple filters and a few relationships.
Thats how my model view looks like at the moment. And I'm trying to count Audits based on DateAuditDue as one filter, and then the AccreditationCategory in CompanyInfo table should match CategoryName in AccreditationCategories table.
The table CompanyInfo doesn't have CategoriesID, that's why I need to match strings and for doing so I need to go through ProgramAccreditationCategories table, which has a many to many relationship with CompanyInfo.
This may seem overcomplicated, but in SQL would be something like:
select * from AuditHeader
join CompanyInfo C on CompanyID
join ProgramAccreditationCategories PAC on ProgramGUID
join AccreditationCategories AC on PAC.OverdueAccreditationCategory = AC.Id
where C.AccreditationCategory = AC.CategoryName
So the joins would be automatically filtered.
In DAX I have this:
Solved! Go to Solution.
Hey @DJ_Paxton ,
first, welcome to Power BI!
Then, ...
There are at least two things that you have to consider iin your measure.
Additionally, due to the many-to-many relationship columns from the one-side (no matter of the depth of the relationships) are not extended to the table of the many side of the relationship. For this reason you have to write your measure slightly different. You can read about the concept of the extended table here: Extended tables - the sword by my side - Mincing Data - Gain Insight from Data (minceddata.info)
Consider rewriting the table filter of your measure like so:
measure =
CALCULATE(
...,
CALCULATETABLE(
ALL( CompanyInfo[AccreditationCategory]),
TREATAS( VALIUES(AccreditationCategories[CategoryName]), CompanyInfo[AccreditationCategory] )
)
Read about TREATAS here: TREATAS – DAX Guide
What it does it passes a table to a column, and then values of the table are used to filter the table.
If this does not work, consider to create a pbix file that contains sample data but still reflects your semantic model (tables, relationships, calculated columns, and measures) upload the pbix to OneDrive, Google Drive, or Dropbox and share the link. If you are use a spreadsheet to import the sample data instead of using the manual input method share the spreadsheet as well.
Hopfully, this helps to tackle your challenge.
Regards,
Tom
Hey @DJ_Paxton ,
first, welcome to Power BI!
Then, ...
There are at least two things that you have to consider iin your measure.
Additionally, due to the many-to-many relationship columns from the one-side (no matter of the depth of the relationships) are not extended to the table of the many side of the relationship. For this reason you have to write your measure slightly different. You can read about the concept of the extended table here: Extended tables - the sword by my side - Mincing Data - Gain Insight from Data (minceddata.info)
Consider rewriting the table filter of your measure like so:
measure =
CALCULATE(
...,
CALCULATETABLE(
ALL( CompanyInfo[AccreditationCategory]),
TREATAS( VALIUES(AccreditationCategories[CategoryName]), CompanyInfo[AccreditationCategory] )
)
Read about TREATAS here: TREATAS – DAX Guide
What it does it passes a table to a column, and then values of the table are used to filter the table.
If this does not work, consider to create a pbix file that contains sample data but still reflects your semantic model (tables, relationships, calculated columns, and measures) upload the pbix to OneDrive, Google Drive, or Dropbox and share the link. If you are use a spreadsheet to import the sample data instead of using the manual input method share the spreadsheet as well.
Hopfully, this helps to tackle your challenge.
Regards,
Tom
First thing to mention is that when you call a measure, you don't call the 'home table' of the measure. So you can change _mAuditHeader[AuditCount] to just [AuditCount]
Next thing to consider. Power BI works best using a Star Schema. Typically if you find yourself with a many to many relationship, you have made a modelling mistake and need to reconsider your approach. Power BI is not a database, so you want to denormalise where possible and get back to a star schema (or if necessary snowflake).
User | Count |
---|---|
85 | |
80 | |
77 | |
49 | |
41 |
User | Count |
---|---|
114 | |
56 | |
51 | |
42 | |
42 |