Forum Discussion
Anonymous
4 years agoNot applicable
FILTER /w string variable
Hi all, I'm facing a puzzle which i haven't been able to solve / google for 2 days now even though I feel it should be easy to accomplish. Quick explanation: im trying to train my DAX skills...
- Anonymous4 years ago
Hi Anonymous ,
As far as I know Power BI doesn't support us to create calcualted table to show dynamic results. Here I have a workaround. I suggest you to create a 'Goods' table with all items and ingredients in 'Product' table.
Item and Ingredient = VAR _UNION = UNION ( VALUES ( Products[Item] ), VALUES ( Products[Ingredient 1] ), VALUES ( Products[Alternative ingr 2] ), VALUES ( Products[Alternative ingr 3] ) ) VAR _FILTER = SUMMARIZE ( FILTER ( _UNION, [Item] <> BLANK () ), [Item] ) RETURN _FILTERThen create a measure to filter this table.
Filter = VAR _ITEM = SELECTEDVALUE ( Products[Item] ) VAR _Ingredient1 = SELECTEDVALUE ( Products[Ingredient 1] ) VAR _Ingredient2 = SELECTEDVALUE ( Products[Ingredient 2] ) VAR _Ingredient3 = SELECTEDVALUE ( Products[Ingredient 3] ) VAR _CURRENTVALUE = MAX ( 'Item and Ingredient'[Goods] ) RETURN IF ( _CURRENTVALUE = _ITEM || _CURRENTVALUE = _Ingredient1 || _CURRENTVALUE = _Ingredient2 || _CURRENTVALUE = _Ingredient3, 1, 0 )Add this measure into visual level filter and set it to show items when value = 1.
Result is as below. When I select Rum in slicer, we can see Rum/Wood and Suger cane in table.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Whitewater100
4 years agoSolution Sage
Hi Ramon:
Do you have a way to set up some tables to help with your question? I'll paste below one way to lay out the model foundation to make the job easier:
| Dim_Components | ||||||
| Prduct_ID | Product | Component | Share | Cost(Optional) | ||
| 1 | Rum | Wood | 0.1 | |||
| 1 | Rum | Sugar | 0.4 | |||
| 1 | Rum | Water | 0.5 | |||
| 2 | Bread | Wheat | 0.25 | |||
| 2 | Bread | Flour | 0.25 | |||
| 2 | Bread | Yeast | 0.25 | |||
| 2 | Bread | Milk | 0.25 | |||
| 3 | Other | A | 0.33 | |||
| 3 | Other | B | 0.33 | |||
| 3 | Other | C | 0.33 | |||
| Dim_Products | ||||||
| Prod_ID | Name | Sell_Price | ||||
| 1 | Rum | 20 | ||||
| 2 | Bread | 3 | ||||
| 3 | Other | 10 | ||||
| Fact Sales | ||||||
| Cust_ID | Prod_ID | Trans Date | Qty | |||
| other potential Dim Tables - "Dates" & "Customers" | ||||||