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
Maricel
Frequent Visitor

How to FORMAT or VALUE my SWITCH formula?

Hi everybody,

 

I need to classified the difference between 2 dates: today and the last order date.

Ir order to do so, I was trying to use this DAX formula:

 

Serves Clasification =

    var Daywithoutserve= [Días sin pedir]
    var Status=
        SWITCH([Días sin pedir],
                Consumo[Consumo diario en el último años]<=30, "No servir",
                Consumo[Consumo diario en el último años]<=60, "Posible",
                Consumo[Consumo diario en el último años]<=90, "Servir"
                )
return  
Estado
 
Power Bi says is impossible to the switch funtion compare between Integer and TRUE/FALSE values, that I should try use FORMAT or VALUE funtion to conver the data. But I have no idea how to use these funtioncs.

Could someone help me please?
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Maricel 

is this a measure or a calculated? The variable Daywithoutserve is not used. The syntax of the SWITCH statement is not correct, normally it should be  SWITCH ( TRUE (), ...... however, it is not clear what are you trying to achieve by inserting the [Días sin pedir] measure into the switch statement. What is Estado?

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @Maricel 

[Días sin pedir] is of integer type and result of Consumo[Consumo diario en el último años]<=??  is of type boolean, so you can't compare them.

If [Días sin pedir] is the difference between the two dates, you can try something like:
Measure:

Serves Clasification =
VAR Daywithoutserve = [Días sin pedir]
VAR Status =
    SWITCH (
        TRUE (),
        Daywithoutserve <= 30, "No servir",
        Daywithoutserve <= 60, "Posible",
        Daywithoutserve <= 90, "Servir"
    )
RETURN
    Estado

Best Regards,
Community Support Team _ Eason

tamerj1
Super User
Super User

Hi @Maricel 

is this a measure or a calculated? The variable Daywithoutserve is not used. The syntax of the SWITCH statement is not correct, normally it should be  SWITCH ( TRUE (), ...... however, it is not clear what are you trying to achieve by inserting the [Días sin pedir] measure into the switch statement. What is Estado?

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.

Top Solution Authors