Forum Discussion

arcegabriel's avatar
arcegabriel
Helper I
5 years ago
Solved

Problems using SELECTEDVALUE in DAX

I am having an issue using selectedvalue function from a slicer. 

 

Table name is RegionTable

Region field contains US, Canada, EMEA, APAC

This table is used as a slicer

 

I want to assign an attribute in a different table based on the slicer and using DAX

 

Table name is SalesTable

Numerous fields

OriginatingRegion field exist

DestinationRegion field exist

 

I would like to add two new columns

OriginitatingRegionFlag = 25 if OriginatingRegion = selectedvalue on RegionTable otherwise OriginitatingRegionFlag = 10

DestinationRegionFlag = 25 if DestinationRegionFlag = selectedvalue on RegionTable otherwise DestinationRegionFlag = 10

 

For some reason this doesn't work. It seems that DAX does not like selectedvalue in formulas. If I add a column to show selectedvalue it always shows Blank

 

However, if add a measure for selectedvalues and then add it to a card it shows well

 

Any asistance is appreciated. I thought this would be simple 😞

  • arcegabriel In theory something along the lines of:

    OriginitatingRegionFlag = IF(MAX('Table'[OriginatingRegion]) = SELECTEDVALUE('Table1'[OriginatingRegion]),25,10)
    
    DestinationRegionFlag = IF(MAX('Table'[DestinationRegion]) = SELECTEDVALUE('Table1'[OriginatingRegion]),25,10)

5 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    arcegabriel Calculated columns are only re-calculated at the time of data refresh and thus are unaffected by dynamic things like user interaction. SELECTEDVALUE is a function meant to be used in measures. You will need to use measures to accomplish what you want to achieve.

  • Thanks I understand but terribly lost on how to do that with measures. 

    Appreciate any suggestions or a nudge on the right direction

    • Greg_Deckler's avatar
      Greg_Deckler
      Community Champion

      arcegabriel In theory something along the lines of:

      OriginitatingRegionFlag = IF(MAX('Table'[OriginatingRegion]) = SELECTEDVALUE('Table1'[OriginatingRegion]),25,10)
      
      DestinationRegionFlag = IF(MAX('Table'[DestinationRegion]) = SELECTEDVALUE('Table1'[OriginatingRegion]),25,10)
      • arcegabriel's avatar
        arcegabriel
        Helper I

        Thanks, this worked well for me (had to make some adjustments to align with my model). Appreciate it