Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX Measure error - to remove fixed values with table column fields

Hi Experts

 

The following measure currently has fixed values i want to changes thes to table column fields.

 

Current MEasure

Measure 2 = 
VAR _CountryStore = "(Cananda),(Italy);[004],[005]"
VAR SeparatorPosition =
    SEARCH ( ";", _CountryStore )
VAR _Length =
    LEN ( _CountryStore )
VAR _Country =
    LEFT ( _CountryStore, SeparatorPosition - 1 )
VAR _Store =
    MID ( _CountryStore, SeparatorPosition + 1, _Length - SeparatorPosition )
RETURN
    CONCATENATE ( _Country, CONCATENATE ( ";", _Store))

 

I want to replace 

VAR _CountryStore = "(Cananda),(Italy);[004],[005]"
 
With pg_control[Country] where teh above is(Cananda),(Italy)
ps_control[store] where[004],[005]
as opposited to fixed values in the variable
  • johnt75's avatar
    johnt75
    3 years ago

    You could try something like

    Selected countries and stores =
    VAR _Countries =
    	"( "
    		& CONCATENATEX(
    			VALUES( 'pg_control_cases'[country_dim.country_name] ),
    			'pg_control_cases'[country_dim.country_name],
    			","
    		)
    		& " )"
    VAR _Stores =
    	"( "
    		& CONCATENATEX(
    			VALUES( 'pg_control_cases'[bu_code] ),
    			'pg_control_cases'[bu_code],
    			", "
    		)
    		& " )"
    RETURN
    	_Countries & ";" & _Stores

10 Replies

  • Why do you need to split them if they are already in separate columns ?

    • Anonymous's avatar
      Anonymous
      Not applicable

      My question is how do i make the following dynamic based on slicer selction not fixed value in 

      VAR _CountryStore = "(Cananda),(Italy);[004],[005]"

       

      The Country values come from 

      With pg_control[Country] and store from 
      ps_control[store]
      • johnt75's avatar
        johnt75
        Super User

        You can use SELECTEDVALUE

        VAR _Country =  SELECTEDVALUE('pg_control'[Country])
        VAR _Store = SELECTEDVALUE('ps_control'[store])
    • johnt75's avatar
      johnt75
      Super User

      You could try something like

      Selected countries and stores =
      VAR _Countries =
      	"( "
      		& CONCATENATEX(
      			VALUES( 'pg_control_cases'[country_dim.country_name] ),
      			'pg_control_cases'[country_dim.country_name],
      			","
      		)
      		& " )"
      VAR _Stores =
      	"( "
      		& CONCATENATEX(
      			VALUES( 'pg_control_cases'[bu_code] ),
      			'pg_control_cases'[bu_code],
      			", "
      		)
      		& " )"
      RETURN
      	_Countries & ";" & _Stores
      • Anonymous's avatar
        Anonymous
        Not applicable

        perfect