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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

EN ESPAÑOL - PROBLEMA CON CONDICIONALES

Buenos días,

 

soy nueva en power BI y no entiendo muy bien el lenguaje de DAX.

Estoy haciendo una medida para que una columna se ponga de un color u otro dependiendo del valor que tenga.

De momento he hecho esto:

COLOR= SWITCH(TRUE(), SUM(COSTE) > SUM (META COSTE), "#039800", SUM(COSTE)< SUM(META COSTE), "#DF0000")

Es decir, que si mi coste es mayor que la meta, se ponga de un color, pero si es menor se ponga de otro. Hasta aquí todo bien.

Pero necesito hacer un doble condicional, es decir, necesito poner que si el coste> a la meta se ponga de un color, pero que si el coste es < que la meta Y ADEMÁS > coste del año anterior se ponga en otro color, y que si el coste es< que la meta Y ADEMÁS < que el coste del año anterior se ponga de otro distinto. Es decir, 3 colores

 

Lo he intententado de varias formas y no hay manera con ese formato, muchas gracias por la ayuda.

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , Based on what I got so far.

 

You can add additional condition is and && or OR ||

 

COLOR= SWITCH(TRUE(), SUM(COSTE) > SUM (META COSTE) && SUM(Previous year COSTE) > SUM (META COSTE) , "#039800",

SUM(COSTE)< SUM(META COSTE), "#DF0000")

 

 

for last year cost you can use time intelligence with date table

 

 

example

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

View solution in original post

v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have built a data sample,

Eyelyn9_0-1638252270204.png

                       ......

Eyelyn9_1-1638252281948.png

Please follow @amitchandak 's suggestion to calculate the last year cost:

Last year cost = CALCULATE(SUM('Table'[Cost]),SAMEPERIODLASTYEAR('Table'[Date]))

Then try:

Color = 
var _cost=SUM('Table'[Cost])
var _target=SUM('Table'[Target])
return 
SWITCH(TRUE(), _cost>_target,"Red", _cost<_target && _cost>[Last year cost], "Green", _cost<=_target &&_cost<=[Last year cost], "Yellow")

 

Eyelyn9_2-1638252432548.png

 

 

Best Regards,
Eyelyn Qin
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

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have built a data sample,

Eyelyn9_0-1638252270204.png

                       ......

Eyelyn9_1-1638252281948.png

Please follow @amitchandak 's suggestion to calculate the last year cost:

Last year cost = CALCULATE(SUM('Table'[Cost]),SAMEPERIODLASTYEAR('Table'[Date]))

Then try:

Color = 
var _cost=SUM('Table'[Cost])
var _target=SUM('Table'[Target])
return 
SWITCH(TRUE(), _cost>_target,"Red", _cost<_target && _cost>[Last year cost], "Green", _cost<=_target &&_cost<=[Last year cost], "Yellow")

 

Eyelyn9_2-1638252432548.png

 

 

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

amitchandak
Super User
Super User

@Anonymous , Based on what I got so far.

 

You can add additional condition is and && or OR ||

 

COLOR= SWITCH(TRUE(), SUM(COSTE) > SUM (META COSTE) && SUM(Previous year COSTE) > SUM (META COSTE) , "#039800",

SUM(COSTE)< SUM(META COSTE), "#DF0000")

 

 

for last year cost you can use time intelligence with date table

 

 

example

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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