Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi all,
I'm stuck on a DAX issue relating to filter context - have tried a few ways with little success.
I'm building the table below in Power BI which only allows single select on the slicer, which in this case is Kitchen. I'm struggling to calculate the last column 'Other Active Products' which sums all of the rows for the sales agent which do not equal kitchen but all other filters will be applied.
Sales Agent | Product | Volume Sold | Other Active Products |
Sales agent 1 | Kitchen | 1 | 2 |
Sales agent 2 | Kitchen | 13 | 1 |
Sales agent 3 | Kitchen | 22 | 4 |
An example of the underlying data is below and I'm trying to sum 'Active Product'.
Sales Agent | Product | Active Product | Volume Sold |
Sales agent 1 | Kitchen | 1 | 1 |
Sales agent 1 | Sofa | 1 | 4 |
Sales agent 1 | TV | 0 | 7 |
Sales agent 1 | Bathroom | 1 | 10 |
Sales agent 2 | Kitchen | 1 | 13 |
Sales agent 2 | Sofa | 1 | 16 |
Sales agent 2 | TV | 0 | 19 |
Sales agent 3 | Kitchen | 1 | 22 |
Sales agent 3 | Sofa | 1 | 25 |
Sales agent 3 | TV | 0 | 28 |
Sales agent 3 | Bathroom | 1 | 31 |
Sales agent 3 | Bed | 1 | 34 |
Any help would be greatly appreciated 🙂
Solved! Go to Solution.
Hi @Jim_PBI
Due to you use All function, you need to add a filter 'Table'[Sales Agent]=MAX('Table'[Sales Agent]) in your code to calculate sum 'Active Product' for each Sales Agent.
Other Active Products =
VAR _SELECTVALUE =
SELECTEDVALUE ( 'Table'[Product] )
VAR _SUM =
CALCULATE (
SUM ( 'Table'[Active Product] ),
FILTER (
ALL ( 'Table' ),
'Table'[Product] <> _SELECTVALUE
&& 'Table'[Sales Agent] = MAX ( 'Table'[Sales Agent] )
)
)
RETURN
_SUM
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Please consider and adapt this solution and click the thumbs up and accepts the the solution
I think this is very close to what I need so thank you for the response. In my real life scenario my data model is across two tables with a DIM table for the sales agents with a many to one relationship using the unique key. The slicer on the page is for the 'Sales Agent' from the DIM table and I believe this is stopping the DAX working correctly on the FACT table. I have included my DIM table below.
Unique Key | Sales Agent |
123 | Sales agent 1 |
124 | Sales agent 2 |
125 | Sales agent 3 |
Hi @Jim_PBI
Due to you use All function, you need to add a filter 'Table'[Sales Agent]=MAX('Table'[Sales Agent]) in your code to calculate sum 'Active Product' for each Sales Agent.
Other Active Products =
VAR _SELECTVALUE =
SELECTEDVALUE ( 'Table'[Product] )
VAR _SUM =
CALCULATE (
SUM ( 'Table'[Active Product] ),
FILTER (
ALL ( 'Table' ),
'Table'[Product] <> _SELECTVALUE
&& 'Table'[Sales Agent] = MAX ( 'Table'[Sales Agent] )
)
)
RETURN
_SUM
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Many thanks for the solution 🙂
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
136 | |
118 | |
101 | |
71 | |
61 |