Forum Discussion

user01's avatar
user01
Icon for Resolver I rankResolver I
1 year ago
Solved

Create a measure that returns values like a Field Parameter does

I have some dummy data below. I imported the example from Excel, but the true data will come from SQL Server via DirectQuery.

 

I have a slicer for Category and a slicer for the Field Parameter. The Field Parameter uses Amount column and Employee column. The Field Parameter is called "View" in my example.

 

I put the actual columns and the Field Parameter in a Table visualization. I want to create a measure that returns values like the Field Parameter does ("Desired" column in attached image). So, if the user chooses Amount, the desired measure returns the value for Amount, and similarly for Employee.

 

I'm trying to figure out a workaround for conditional formatting. I cannot link to my main issue right now because it was marked as spam.

 

Desired Example:

 

Dummy data:

CategoryStateEmployeeAmount
AVirginia681114208
AUtah1441075717
AMichigan381074534
AIllinois1151074214
ANevada1041067658
AMassachusetts931065064
ANew Hampshire421005700
ACalifornia105946129
AMaine101905930
AWashington134878621
ANew Jersey76851987
APennsylvania110850507
AWest Virginia77828861
ARhode Island88811964
AConnecticut70802208
ANew York129798794
ADelaware114783194
AIdaho18734638
AMaryland125706365
ATennessee69688048
AWisconsin97668750
AKansas65665809
AMississippi132580631
AVermont106575309
AGeorgia177520854
BWisconsin971706845
BMassachusetts931477807
BMaine1011394473
BIdaho181358479
BRhode Island881184244
BNew Jersey761177116
BUtah1441143117
BTennessee691084389
BPennsylvania1101032075
BWest Virginia77892761
BConnecticut70865538
BKansas65864826
BVirginia68862125
BCalifornia105848612
BNew York129818033
BWashington134764280
BMaryland125710922
BGeorgia177708657
BVermont106698224
BIllinois115695709
BMississippi132675824
BDelaware114657883
BMichigan38630631
BNevada104539081
BNew Hampshire42484559
  • user01's avatar
    user01
    1 year ago

    Anonymous 
    I made a change to your code and it worked. But do you know why it did not work when I did it your way?

    SelectedValueMeasure =
    SWITCH(
        TRUE(),
        SELECTEDVALUE('Parameter'[Parameter Fields]) = "'Table'[Amount]", SUM('Table'[Amount]),
        SELECTEDVALUE('Parameter'[Parameter Fields]) = "'Table'[Employee]", SUM('Table'[Employee])
    )

     

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi user01 ,

    I create a table as you mentioned.

    Then I think you can create a measure and here is the DAX code.

    SelectedValueMeasure = 
    SWITCH(
        TRUE(),
        SELECTEDVALUE('Parameter'[Parameter]) = "Amount", SUM('Table'[Amount]),
        SELECTEDVALUE('Parameter'[Parameter]) = "Employee", SUM('Table'[Employee])
    )

    You can use them and it will give you what you want.

     

     

    Best Regards

    Yilong Zhou

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • user01's avatar
      user01
      Icon for Resolver I rankResolver I

      Anonymous 

      I got the following error:

       

      Error fetching data for this visual

      MdxScript(Model) (12, 5) Calculation error in measure 'Data2'[SelectedValueMeasure]: Column

      [Parameter] is part of composite key, but not all columns of the composite key are included in the

      expression or its dependent expression.

       

    • user01's avatar
      user01
      Icon for Resolver I rankResolver I

      Anonymous 
      I made a change to your code and it worked. But do you know why it did not work when I did it your way?

      SelectedValueMeasure =
      SWITCH(
          TRUE(),
          SELECTEDVALUE('Parameter'[Parameter Fields]) = "'Table'[Amount]", SUM('Table'[Amount]),
          SELECTEDVALUE('Parameter'[Parameter Fields]) = "'Table'[Employee]", SUM('Table'[Employee])
      )

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi user01 ,

        From the error message, the problem is because the Parameter column is part of the composite key and your expression does not contain all the columns of the composite key.

         

        So it needs to be presented with the full column, like the 'Table'[Amount] you modified.

         

         

        Best Regards

        Yilong Zhou

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.