Forum Discussion

PwrBI01's avatar
PwrBI01
Post Patron
5 years ago
Solved

Different formats in switch function

Hi guys,

 

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

 

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:
 
Thanks in advance.
 
Regards.
  • 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.

5 Replies

    • PwrBI01's avatar
      PwrBI01
      Post Patron

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

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

    • PwrBI01's avatar
      PwrBI01
      Post Patron

      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.
      • Tahreem24's avatar
        Tahreem24
        Super User

        PwrBI01  Great!

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