Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I've got my data structured as below in a contractProducts table, gives each combination of contract and product as well as the previous product for each contract (each contract can have more than one product).
contract_id | product_id | previous_product_id |
1 | 1 | 1 |
2 | 2 | 1 |
2 | 3 | 3 |
3 | 3 | 2 |
4 | 1 | 3 |
5 | 3 | 1 |
6 | 2 | 3 |
6 | 1 | 2 |
7 | 3 | 3 |
8 | 1 | 1 |
9 | 1 | 2 |
9 | 2 | 3 |
10 | 3 | 1 |
I've also got a product benefits table (below), showing all the benefits selected for each product.
product_id | benefit_name |
1 | legs |
1 | arms |
1 | head |
1 | back |
2 | legs |
2 | arms |
2 | hands |
2 | feet |
3 | legs |
3 | hands |
3 | eyes |
3 | left kidney |
These have a many-many relationship between them based on the product id on each, I'd love to be able to refactor it or somehow split it all out to a much more sensible model, but due to the system I'm working with and how the benefits are structured and attached to product information that isn't feasible (I've tried but this is as close as it gets, long story short is that it's not really possible to make a unique list of benefits and/or products in a way that keeps the information correct).
What I want in power Bi is a matrix that shows each contract, which can expand to show all of their product benefits for their current product, and check whether each benefit is new (based on the previous product id) (picture below, as an image to make it easier to see how the matrix works, won't be entirely the same as the data above):
Essentially, I want a measure that finds:
For each product they have
For each benefit in that product
Hi @ajc96 -Compare the current benefit to the previous product’s benefits using CONTAINS or a similar DAX function.
Create measure:
IsNewBenefit =
VAR currentProductID = SELECTEDVALUE(contractProducts[product_id])
VAR previousProductID = SELECTEDVALUE(contractProducts[previous_product_id])
VAR currentBenefit = SELECTEDVALUE(productBenefits[benefit_name])
-- Get the benefits of the previous product
VAR previousProductBenefits =
CALCULATETABLE(
VALUES(productBenefits[benefit_name]),
productBenefits[product_id] = previousProductID
)
-- Check if the current benefit exists in the previous product's benefits
VAR isNewBenefit =
IF(
NOT CONTAINS(previousProductBenefits, productBenefits[benefit_name], currentBenefit),
"Yes", -- Benefit is new
"No" -- Benefit exists in the previous product
)
RETURN isNewBenefit
Let me know if this works for your setup, if any please share more references and details.
Proud to be a Super User! | |
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
110 | |
102 | |
99 | |
38 | |
37 |
User | Count |
---|---|
158 | |
125 | |
76 | |
74 | |
63 |