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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Need help with DAX code, performance problem

See the description of the problem below, "Metric_to_Show" in the red box.
As you can see I have one solution that is working fast if I use the actual metric,
but when I replace the actual metric with my dynamic selection it is slow.

So my Q is why is it not working with ’Dynamic_Metrics’[Metric to show]?

 

tobiasnygren_0-1609858976787.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I have found the problem in the switch statement.
After changing the switch statement to this, it is working.
Metric to show:=
SWITCH(
SELECTEDVALUE(Dynamic_Metrics[Metric Name], "All/No selected"),
"# of rows with Police dispatched by",[# of rows with Police dispatched by],
"# of rows with Fire dispatched by",[# of rows with Fire dispatched by],
"# of rows with Guard dispatched by",[# of rows with Guard dispatched by],
"# of rows with Guard dispatched cancelled by",[# of rows with Guard dispatched cancelled by],
"# of rows with Sms sent by",[# of rows with Sms sent by],
"# of rows with First ACK by",[# of rows with First ACK by],
[# of rows with Guard dispatched by]
)

View solution in original post

5 REPLIES 5
AlB
Community Champion
Community Champion

@Anonymous 

You have to share the URL to the file hosted elsewhere: Dropbox, Onedrive... or just upload the file to a site like tinyupload.com (no sign-up required).

AlB
Community Champion
Community Champion

Hi @Anonymous 

Can you share the pbix? Otherwise:

Can you show the code for [Selected Metric Name]?

Can you show where you are using the measure (what visual, what fields are in the visual and the relevant tables)?

What exactly do you mean by "keep my filters"?

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

 

 

Anonymous
Not applicable

I have created a testfile, but I can't find how to upload it here. Do you know how to do that?

Anonymous
Not applicable

I have found the problem in the switch statement.
After changing the switch statement to this, it is working.
Metric to show:=
SWITCH(
SELECTEDVALUE(Dynamic_Metrics[Metric Name], "All/No selected"),
"# of rows with Police dispatched by",[# of rows with Police dispatched by],
"# of rows with Fire dispatched by",[# of rows with Fire dispatched by],
"# of rows with Guard dispatched by",[# of rows with Guard dispatched by],
"# of rows with Guard dispatched cancelled by",[# of rows with Guard dispatched cancelled by],
"# of rows with Sms sent by",[# of rows with Sms sent by],
"# of rows with First ACK by",[# of rows with First ACK by],
[# of rows with Guard dispatched by]
)

Anonymous
Not applicable

Sorry, I can't share the pbix.
The model is build in SSAS also.
But I can share the code 😃
Selected Metric Name:= SELECTEDVALUE(Dynamic_Metrics[Metric Name], "No selected")


And I select the Metric Name from a slicer in the pbix.

tobiasnygren_0-1609883289239.png

 



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.