0
votes

I have created this table in Power BI:

DimProduct = UNION(
    ROW("ProductId", 1, "Product", "AB","ProductType","A"),
    ROW("ProductId", 2, "Product", "AC","ProductType","A"),
    ROW("ProductId", 3, "Product", "AD","ProductType","A"),
    ROW("ProductId", 4, "Product", "BB","ProductType","B"),
    ROW("ProductId", 5, "Product", "BC","ProductType","B")
)

Then I created this table:

DimProductSelectedType = 
VAR vSelectedProduct=
    SELECTEDVALUE('DimProduct'[Product])

RETURN
ROW("Col1",vSelectedProduct)

I dropped DimProduct[Product] into a slicer

I dropped DimProductSelectedType into a list

I expect that when I pick one product from the product slicer, it will appear in the list. But the list always remains blank.

I had thought that SELECTEDVALUE would reflect any single value picked in a slicer

That's my immediate problem, and this can be summarized as

Table columns that use DAX calcs are evaluated at import time. Measure are evaluated at runtime

What I'm actually working towards is:

  1. Pick a product in a slicer
  2. Identify that products product type
  3. Show visualisations comparing selected product compared to all other products within that product type

I actually started with this and now I'm working my way back.

DimProductTypeSelected = 
VAR vSelectedProduct=
    SELECTEDVALUE('DimProduct'[Product])

VAR vSelectedProductType=
  SUMMARIZE(  
    FILTER(
        ALLSELECTED(DimProduct),
        DimProduct[Product]=vSelectedProduct
        ),
    DimProduct[ProductType]
  )


RETURN
FILTER(
    ALLSELECTED(DimProduct),
    DimProduct[ProductType]=vSelectedProductType
    )
1

1 Answers

0
votes

When you select item in a slicer it already creates fitler context on other visuals, so there is no need to overwrite it manually. What you would need to do is to create a fitler context for all products, e.g. by using ALL or ALLSELECTED for the comparators. But in order for this to be dynamic you need to use measures, tables are static and do not recalculate with UI changes.

To explain why you get your results with your current approach - tables are refreshed once and do not change afterwards. Therefore vSelectedProduct always returns blank, as at the moment of refreshing this table there is no filter context on the DimProduct[Product], so it defaults to blank

If you create a measure Measure = SELECTEDVALUE('DimProduct'[Product]) and put DimProduct[Product] into a slicer it will show the selected product for a single select and blank for multiselect (or all values)

EDIT Regarding the second part of your question - selecting a product will create a filter context only for that product in the other visuals. Then you could use e.g.:

CountRowsPerType = 
VAR vSelectedType =
    SELECTEDVALUE('DimProduct'[ProductType])
RETURN
CALCULATE( COUNTROWS(DimProduct), ALL(DimProduct[Product]), 'DimProduct'[ProductType] = vSelectedType )

which will return count for all the products of that type even though the visual will only show the selected product