Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
2 years ago

Splitting with text

Good day I would like your support in solving the following question within power bi.

I need to divide the number of hours worked by 8 but I have workers who have a 12-hour shift and these need to be divided by 12 which differentiates them from the others are 4 different positions within the company.

How might this division be applied?

7 Replies

  • rsbin's avatar
    rsbin
    Community Champion

    Syndicate_Admin ,

    Assuming you have "Position" as as a field in your table, you can create a calculated column using the Switch function.  So something like this:

    NewColumn = SWITCH(
                   TRUE()
                [Position] = "A", Divide( [Hours], 12, 0 ),
                [Position] = "B", Divide( [Hours], 12, 0 ),
                [Position] = "C", Divide( [Hours], 12, 0 ),
                [Position] = "D", Divide( [Hours], 12, 0 ),
                 Divide( [Hours],8, 0 )

    If you are comfortable, you can combine the first 4 conditions into 1 using the OR Statement.

    Hope this gets you what you are after.

    Regards,

  • I've tried to enter as you indicate, it would be like that, right?

    In the red column is the total hours and the green column would be where the conditional division would have to go with those 4 positions.

    • rsbin's avatar
      rsbin
      Community Champion

      Syndicate_Admin ,

      You have misunderstood the syntax.

      [Position] is the name of the field.  So in your case I assume this to be [Trajadore].

      I have used the letters A, B, C, D as placeholders for the actual text of the Positions that need to be divided by 12.

      So instead of "A", you enter "....Operador Filtrado ".

      Instead of "B", you enter "Fertilizacion".  Enter the text exactly how it appears in your [Trabajado] column.
      Use the exact text of the position

  • I understand in my case the place where the filtering would be is in the work column I have placed it and it throws an error in syntaxy

    Wages = SWITCH(
    TRUE()
    [Labor] = "FERTIGATION CONTROL-FILTERED OPERATOR", DIVIDE( Append1[Effective Hours], 12, 0),
    [Labor] = "FERTILIZATION", DIVIDE( Append1[Effective Hours], 12, 0),
    [Labor] = "IRRIGATION SYSTEM MAINTENANCE", DIVIDE( Append1[Effective Hours], 12, 0),
    [Labor] = "OPERATOR INFRA. OF IRRIGATION AND HYDRA.", DIVIDE( Append 1[Effective Hours], 12, 0),
    DIVIDE(Append1[Effective Hours],8,0))

    • rsbin's avatar
      rsbin
      Community Champion

      Syndicate_Admin ,

      Think you are missing a comma "," after TRUE()

      Please try this:  Wages = SWITCH(
                                                    TRUE(),

    • rsbin's avatar
      rsbin
      Community Champion

      Syndicate_Admin ,

      Please "Accept as Solution" to close this thread and give Kudos if you feel like doing so.

      Kind Regards,