Forum Discussion

tmears's avatar
tmears
Helper III
8 years ago
Solved

IF statement maybe?

 

Hi all

 

I have a problem wondering if anyone could make any suggestions or help?? 

I have the following calcuated column:

 

FirstDayEndTime =
DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon]  ), DAY ( incident[createdon]  ) )
& " 17:00:00"

 

the problem i have is that different customers have different end times, could i do a IF statement on a customer name to generate a different end time specific to individual customers?  or any other suggestions??

  • Hi tmears

     

    From my point of view ...

    if you know and can assign to each customer a range hour.

    Let's say all the customers that end their hours at 17:00 could be assigned 'Type A', and all those that end their hours at 18:00 could be assigned 'Type B'

    Then you could use ....

    FirstDayEndTime =
    IF(
        Customers[Type] = "Type A",
        DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon]  ), DAY ( incident[createdon]  ) )

         & " 17:00:00",
        DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon]  ), DAY ( incident[createdon]  ) )
        & " 18:00:00"
    )

    Hope That Helps

    Vicente

  • Hi tmears,

     

    In addition, using SWITCH function should also work. :smileyhappy:

    FirstDayEndTime =
    SWITCH (
        Customers[Type],
        "Type A", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
            & " 17:00:00",
        "Type B", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
            & " 18:00:00",
        "Type C", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
            & " 19:00:00",
        "Type D", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
            & " 20:00:00"
    )
    

     

    Regards

9 Replies

    • tmears's avatar
      tmears
      Helper III

      thanks for the reply, sorry you are right not alot of detail:

       

      i have followed the enlcosed post:

      https://community.powerbi.com/t5/Desktop/Calculate-Date-and-Time-difference-considering-the-weekends-and/td-p/64202

       

      basically i am trying to calcualte the amount of time a service request or case is open for in dynamics.  the above posts works brilliantly however the issue i have is that swome customer have different support hours.  following the post the support hours is 9:00 to 17:00 but some specfic customer have different hours for example 8:00 to 18:00 so the time calcuations on these customer are wrong.  Not sure if possible and have been trying to wrap my brians that if the case relates to customer A the oprnbing hours are changed

      • v-ljerr-msft's avatar
        v-ljerr-msft
        Microsoft Employee

        Hi tmears,

         

        In addition, using SWITCH function should also work. :smileyhappy:

        FirstDayEndTime =
        SWITCH (
            Customers[Type],
            "Type A", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
                & " 17:00:00",
            "Type B", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
                & " 18:00:00",
            "Type C", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
                & " 19:00:00",
            "Type D", DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon] ), DAY ( incident[createdon] ) )
                & " 20:00:00"
        )
        

         

        Regards

  • Hi tmears

     

    From my point of view ...

    if you know and can assign to each customer a range hour.

    Let's say all the customers that end their hours at 17:00 could be assigned 'Type A', and all those that end their hours at 18:00 could be assigned 'Type B'

    Then you could use ....

    FirstDayEndTime =
    IF(
        Customers[Type] = "Type A",
        DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon]  ), DAY ( incident[createdon]  ) )

         & " 17:00:00",
        DATE ( YEAR ( incident[createdon] ), MONTH ( incident[createdon]  ), DAY ( incident[createdon]  ) )
        & " 18:00:00"
    )

    Hope That Helps

    Vicente