Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
user01
Resolver I
Resolver I

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:

user01_0-1735963853654.png

 

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
1 ACCEPTED SOLUTION

@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])
)

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @user01 ,

I create a table as you mentioned.

vyilongmsft_0-1736306507380.png

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.

vyilongmsft_1-1736306670094.pngvyilongmsft_2-1736306690552.png

 

 

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.

@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
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.

@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_0-1736389843770.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors