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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply

Switch Statement - only first line working

Hi,
 
I have an issue with a switch statement.
Basically, I am trying to use the switch as a way of changing the calculation of the column that is storing the values.
 
In the dataset there is a column called 'attribute' and a column called 'values'. There is also an attribute table linked to the 'attribute' field that will tell you the 'Aggregation'.
 
When this aggregation is e.g. 'Count' I want it to use the Count (Distinct) measure.
 
So far it works for whatever the first line is but not the other lines; so I assumed by code was wrong.
Any ideas?
 
Selection of Measure =
SWITCH(TRUE(),
"Allocation" IN ALLSELECTED(Attribute_Table[Aggregation]), [Allocation Calculation],
"Count" IN ALLSELECTED(Attribute_Table[Aggregation]), [Count (Distinct)],
"Weighted Average" IN ALLSELECTED(Attribute_Table[Aggregation]), [Weighted Average %],
"Allocation (per million)" IN ALLSELECTED(Attribute_Table[Aggregation]), [Allocation per m],
"Percentage Sum" IN ALLSELECTED(Attribute_Table[Aggregation]), [Percentage SUM Positive])
1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @knowledgegarage 

 

My guess is you want this

Selection of Measure =
SWITCH(SELECTEDVALUE(Attribute_Table[Aggregation]),
"Allocation" , [Allocation Calculation],
"Count" , [Count (Distinct)],
"Weighted Average" , [Weighted Average %],
"Allocation (per million)" , [Allocation per m],
"Percentage Sum" , [Percentage SUM Positive])

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @knowledgegarage ;

You could change it.

Selection of Measure =
SWITCH (
    SELECTEDVALUE ( Attribute_Table[Aggregation] ),
    "Allocation", [Allocation Calculation],
    "Count", [Count (Distinct)],
    "Weighted Average", FORMAT ( [Weighted Average %], "0.00%" ),
    "Allocation (per million)", [Allocation per m],
    "Percentage Sum", [Percentage SUM Positive]
)

Here i test a simple example.

Selection of Measure = 
SWITCH(SELECTEDVALUE(Attribute_Table[Aggregation]),
"Count" , [Count (Distinct)],
"Weighted Average" ,FORMAT( [Weighted Average %],"0.00%"))

vyalanwumsft_0-1660011197009.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Vera_33
Resident Rockstar
Resident Rockstar

Hi @knowledgegarage 

 

My guess is you want this

Selection of Measure =
SWITCH(SELECTEDVALUE(Attribute_Table[Aggregation]),
"Allocation" , [Allocation Calculation],
"Count" , [Count (Distinct)],
"Weighted Average" , [Weighted Average %],
"Allocation (per million)" , [Allocation per m],
"Percentage Sum" , [Percentage SUM Positive])

Fantastic.

 

Second question, as some of these are % and the others are numerical is there a way of forcing say 'Count Distinct' to be numerical and 'Percentage Sum' to be %?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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