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
PwrBI01
Post Patron
Post Patron

Different formats in switch function

Hi guys,

 

I have used a switch function to create the following table:

Tabla 1.png

 

The switch function I have used is the next one: 

IF(HASONEVALUE('T_M_Tabla indicadores económicos'[Medida]);SWITCH(VALUES('T_M_Tabla indicadores económicos'[Medida]);"Variación prev. año";[Acumulado dos años previos];"% crecimiento";[Acumulado var %];"Importe medio";[Switch importe medio];"% Var importe medio";[Switch importe medio % var];"Variación a fecha";[Acumulado var]))
 
Is there a way to change the formats to get a table similar to the next one:
Tabla 2.png
 
Thanks in advance.
 
Regards.
1 ACCEPTED SOLUTION
Tahreem24
Super User
Super User

@PwrBI01 ,

Create a meaure with the below DAX:

MEASURE = IF(HASONEVALUE('T_M_Tabla indicadores económicos'[Medida]);SWITCH(VALUES('T_M_Tabla indicadores económicos'[Medida]);"Variación prev. año";FORMAT([Acumulado dos años previos],"#.### $");"% crecimiento";FORMAT([Acumulado var %],"Percent");"Importe medio";FORMAT([Switch importe medio],"## $");"% Var importe medio";FORMAT([Switch importe medio % var],"Percent");"Variación a fecha";FORMAT([Acumulado var],"#.### $")))

 

P.S. Just replace the $ sign with Pound sign while writing this dax as per your currency requirement.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

View solution in original post

5 REPLIES 5
Tahreem24
Super User
Super User

@PwrBI01 ,

Create a meaure with the below DAX:

MEASURE = IF(HASONEVALUE('T_M_Tabla indicadores económicos'[Medida]);SWITCH(VALUES('T_M_Tabla indicadores económicos'[Medida]);"Variación prev. año";FORMAT([Acumulado dos años previos],"#.### $");"% crecimiento";FORMAT([Acumulado var %],"Percent");"Importe medio";FORMAT([Switch importe medio],"## $");"% Var importe medio";FORMAT([Switch importe medio % var],"Percent");"Variación a fecha";FORMAT([Acumulado var],"#.### $")))

 

P.S. Just replace the $ sign with Pound sign while writing this dax as per your currency requirement.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Thank you very much @Tahreem24

 

I made some changes (for no decimals in percentages and for get the local format) and it works. The measure I finally used is the next one:

 

Switch prueba = IF(HASONEVALUE('T_M_Tabla indicadores económicos'[Medida]);SWITCH(VALUES('T_M_Tabla indicadores económicos'[Medida]);"Variación prev. año";FORMAT([Acumulado dos años previos];"#,### €");"% crecimiento";FORMAT([Acumulado var %];"#,### %");"Importe medio";FORMAT([Switch importe medio];"#,### €");"% Var importe medio";FORMAT([Switch importe medio % var];"#,### %");"Variación a fecha";FORMAT([Acumulado var];"#,### €")))
 
Regards.

@PwrBI01  Great!

Yeah, I just shared the possible workaround using Format DAX. It's nice that you changed it accordingly to your needs.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
amitchandak
Super User
Super User

Thank you very much for your answer @amitchandak but I would like to do it in a more easy way.

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.