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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Ferha_Jafri
Frequent Visitor

Error in dynamic format

Hello Experst,

 

I am getting below error while using dynamic formatting as 

var selected_toggle = SELECTEDVALUE(View[Value])
var var_value = SWITCH(TRUE(),
selected_toggle = "Total Premium","$#,0" ,
selected_toggle = "Total Incurred", "$#,0" ,
selected_toggle = "No. of Claims", "#,0"
,0
)
 RETURN var_value
 
Dax expression is 
Prem_Cla_Inc toggle =
 var selected_toggle = SELECTEDVALUE(View[Value])
 var var_value = SWITCH(TRUE(),
selected_toggle = "Total Premium",[Sum_Premium],
selected_toggle = "Total Incurred",[Sum_Incured],
selected_toggle = "No. of Claims",[# Claims],0
)
 RETURN var_value
return type for this is a number.
 
Error :
Ferha_Jafri_0-1726331476431.png

Can someone help me as what I am doing wrong here.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Ferha_Jafri 

I’ve provided two solutions for you:

1.Firstly, modify the format as follows:

var selected_toggle1 = SELECTEDVALUE(View[Value])
var var_value1 = SWITCH(TRUE(),
selected_toggle1 = "Total Premium","$#,0" ,
selected_toggle1 = "Total Incurred", "$#,0" ,
selected_toggle1 = "No. of Claims", "#,0"
,"0"
)
 RETURN var_value1

vlinyulumsft_0-1726469186268.png

The error occurred previously because you returned 0 instead of “0”. The output might be a number rather than a string.

 

2.Secondly, directly modify the measure to the following measure:

Measure = 
 var selected_toggle = SELECTEDVALUE(View[Value])
 var var_value = SWITCH(TRUE(),
selected_toggle = "Total Premium",FORMAT([Sum_Premium],"$#,0"),
selected_toggle = "Total Incurred",FORMAT([Sum_Incured],"$#,0"),
selected_toggle = "No. of Claims",FORMAT([# Claims],"#,0"),0
)
 RETURN var_value

This way, the format will be corrected directly when the measure outputs.

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1726469228685.png

vlinyulumsft_2-1726469228686.png

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi, @Ferha_Jafri 

I’ve provided two solutions for you:

1.Firstly, modify the format as follows:

var selected_toggle1 = SELECTEDVALUE(View[Value])
var var_value1 = SWITCH(TRUE(),
selected_toggle1 = "Total Premium","$#,0" ,
selected_toggle1 = "Total Incurred", "$#,0" ,
selected_toggle1 = "No. of Claims", "#,0"
,"0"
)
 RETURN var_value1

vlinyulumsft_0-1726469186268.png

The error occurred previously because you returned 0 instead of “0”. The output might be a number rather than a string.

 

2.Secondly, directly modify the measure to the following measure:

Measure = 
 var selected_toggle = SELECTEDVALUE(View[Value])
 var var_value = SWITCH(TRUE(),
selected_toggle = "Total Premium",FORMAT([Sum_Premium],"$#,0"),
selected_toggle = "Total Incurred",FORMAT([Sum_Incured],"$#,0"),
selected_toggle = "No. of Claims",FORMAT([# Claims],"#,0"),0
)
 RETURN var_value

This way, the format will be corrected directly when the measure outputs.

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1726469228685.png

vlinyulumsft_2-1726469228686.png

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.