Forum Discussion

ChristianAU's avatar
ChristianAU
Frequent Visitor
2 years ago

New costum column

I wish to make a new column with the name “EngagementHours Grouped”, which is dependent on 2 other columns “Attribute” and “Value” from the table “Course data” (same place I want to make the new column).

The code to make the costum column should be something like this, but I can’t seem to make it work:


Table.AddColumn(#"Changed Type4", "EngagementHours Grouped", each let

    Source = #"Course data",

    AddedCustom = Table.AddColumn(Source, "EngagementHours Grouped", each

        if [Attribute] = "EngagementHours" then

            if [Value] >= 0 and [Value] <= 5 then "1: 0-5"

            else if [Value] >= 6 and [Value] <= 10 then "2: 6-10"

            else if [Value] >= 11 and [Value] <= 15 then "3: 11-15"

            else if [Value] >= 16 and [Value] <= 20 then "4: 16-20"

            else if [Value] >= 21 and [Value] <= 25 then "5: 21-25"

            else if [Value] >= 26 and [Value] <= 30 then "6: 26-30"

            else if [Value] >= 31 and [Value] <= 37 then "7: >30"

            else null

        else null)

in

    AddedCustom)

2 Replies

  • ManuelBolz's avatar
    ManuelBolz
    Responsive Resident

    Hello ChristianAU,

    If my post helped you, please give me a 👍kudos and mark this post with Accept as Solution.

    let
        Source = #"Course data",
        AddedCustom = Table.AddColumn(Source, "EngagementHours Grouped", each
            if [Attribute] = "EngagementHours" then
                if [Value] >= 0 and [Value] <= 5 then "1: 0-5"
                else if [Value] >= 6 and [Value] <= 10 then "2: 6-10"
                else if [Value] >= 11 and [Value] <= 15 then "3: 11-15"
                else if [Value] >= 16 and [Value] <= 20 then "4: 16-20"
                else if [Value] >= 21 and [Value] <= 25 then "5: 21-25"
                else if [Value] >= 26 and [Value] <= 30 then "6: 26-30"
                else if [Value] >= 31 and [Value] <= 37 then "7: >30"
                else null
            else null
        )
    in
        AddedCustom


    Best regards from Germany
    Manuel Bolz


    🟦Follow me on LinkedIn
    🟨How to Get Your Question Answered Quickly
    🟩Fabric Community Conference
    🟪My Solutions on Github

    • ChristianAU's avatar
      ChristianAU
      Frequent Visitor

      Thank you for your response. However, i made it work with this solution:

      = let

          Source = #"Changed Type4",

          AddedCustom = Table.AddColumn(Source, "EngagementHours Grouped", each

              if [Attribute] = "EngagementHours" then

                  if [Value] >= 0 and [Value] <= 5 then "1: 0-5"

                  else if [Value] >= 6 and [Value] <= 10 then "2: 6-10"

                  else if [Value] >= 11 and [Value] <= 15 then "3: 11-15"

                  else if [Value] >= 16 and [Value] <= 20 then "4: 16-20"

                  else if [Value] >= 21 and [Value] <= 25 then "5: 21-25"

                  else if [Value] >= 26 and [Value] <= 30 then "6: 26-30"

                  else if [Value] >= 31 then "7: >30"

                  else null

              else null)

      in

          AddedCustom

       

      I tested your solution, and it gave me all errors. I guess you have to make the previous step in power query the source, and not the table itself. Which is weird.