Forum Discussion
Help Required with Removing Visual Filters in Measure
Bit of a strange one this. I have my fact table, Shortfall Items, which is a list of different categories (Works Order, Stock and Purchase Order) and I have this linked to a dimension table for Items, which is essentially a products table with one record per product. They are linked in the model via the item code field.
I then have two tables on a page, one for my items and another for my shortfall items, but that has a visual filter on to only show the category Purchase Order.
The cross filtering works as expected at this point, I select from the items table and the purchase orders table displays all purchase order records for that selected item. So far, so good.
I then needed to create a measure that sums up the Shortfall Items Item Qty field, but not just for Purchase Order records, but for all records in the fact table. On top of this I needed to add a filter to only sum when the date on the fact table record was less than the record in question. Initially I tried the following:
Shortfall Issue Timing Purchase Order Icon =
VAR po_date = MIN('Shortfall Items'[ITEM_DATE])
VAR qty_cltv_prior = CALCULATE(
SUM('Shortfall Items'[ITEM_QTY]),
ALL('Shortfall Items'[ITEM_CATEGORY]),
'Shortfall Items'[ITEM_DATE] < po_date
)
RETURN qty_cltv_prior
However, this resulted in blank values on the Purchase Orders table:
So then I tried a different method, I changed the ALL() from a specific column to just everything. I needed to add in an additional filter to get this to work so that it only summed for the item being cross-filtered:
Shortfall Issue Timing Purchase Order Icon =
VAR po_item = MIN('Shortfall Items'[ITEM_CODE])
VAR po_date = MIN('Shortfall Items'[ITEM_DATE])
VAR qty_cltv_prior = CALCULATE(
SUM('Shortfall Items'[ITEM_QTY]),
ALL(),
'Shortfall Items'[ITEM_DATE] < po_date &&
'Shortfall Items'[ITEM_CODE] = po_item
)
RETURN qty_cltv_prior
This works, as you can see below, but kind of kills performance. It takes a few seconds to load the table when being cross filtered, but if not cross-filtered, can take many seconds to render:
But then it gets weirder. I add on a variable to display an icon depending on whether or not the qty_cltv_prior value is negative or not:
Shortfall Issue Timing Purchase Order Icon =
VAR po_item = MIN('Shortfall Items'[ITEM_CODE])
VAR po_date = MIN('Shortfall Items'[ITEM_DATE])
VAR qty_cltv_prior = CALCULATE(
SUM('Shortfall Items'[ITEM_QTY]),
ALL(),
'Shortfall Items'[ITEM_DATE] < po_date &&
'Shortfall Items'[ITEM_CODE] = po_item
)
VAR icon = IF(qty_cltv_prior < 0, [Clock Bad Icon], [Clock Good Icon])
RETURN icon
It returns all of the fact records, not just the cross filtered ones:
I can get around this by filtering on the Qty Due column to only show values greater than zero, but I don't think this is the solution.
Can anyone explain where I am going wrong, possibly in multiple places! Thanks 🙂
- Anonymous1 year ago
Hi robmarsh ,
Thank you for reaching out! I understand you're facing performance issues and unexpected results.
Please try below DAX which might help you to resolve the issue:Shortfall Issue Timing Purchase Order Icon =
VAR po_item = SELECTEDVALUE('Shortfall Items'[ITEM_CODE])
VAR po_date = MIN('Shortfall Items'[ITEM_DATE])VAR qty_cltv_prior =
CALCULATE(
SUM('Shortfall Items'[ITEM_QTY]),
REMOVEFILTERS('Shortfall Items'[ITEM_CATEGORY]),
'Shortfall Items'[ITEM_DATE] < po_date
)VAR icon = IF(qty_cltv_prior < 0, [Clock Bad Icon], [Clock Good Icon])
RETURN icon
Please feel free to reach us if you still face any issues.
If it resolved your query, consider accepting it as solution.
4 Replies
- AnonymousNot applicable
Hi robmarsh ,
Thank you for reaching out! I understand you're facing performance issues and unexpected results.
Please try below DAX which might help you to resolve the issue:Shortfall Issue Timing Purchase Order Icon =
VAR po_item = SELECTEDVALUE('Shortfall Items'[ITEM_CODE])
VAR po_date = MIN('Shortfall Items'[ITEM_DATE])VAR qty_cltv_prior =
CALCULATE(
SUM('Shortfall Items'[ITEM_QTY]),
REMOVEFILTERS('Shortfall Items'[ITEM_CATEGORY]),
'Shortfall Items'[ITEM_DATE] < po_date
)VAR icon = IF(qty_cltv_prior < 0, [Clock Bad Icon], [Clock Good Icon])
RETURN icon
Please feel free to reach us if you still face any issues.
If it resolved your query, consider accepting it as solution. - AnonymousNot applicable
Hi robmarsh ,
I wanted to check in on your situation regarding the issue. Have you resolved it? If you have, please consider marking the reply that helped you or sharing your solution. It would be greatly appreciated by others in the community who may have the same question.
Thank you. - AnonymousNot applicable
Hi robmarsh ,
As we have not received a response from you yet, I would like to confirm whether you have successfully resolved the issue or if you require further assistance.
If the issue has been resolved, please mark the helpful reply as a "solution" to indicate that the question has been answered and to assist others in the community.
Thank you for your cooperation. Have a great day. - AnonymousNot applicable
Hi robmarsh ,
I wanted to check in on your situation regarding the issue. Have you resolved it? If you have, please consider marking the reply that helped you or sharing your solution. It would be greatly appreciated by others in the community who may have the same question.
Thank you.