Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Transform rows into one column

Hello,

I have a table with the following structure:

Year_MonthTypeValue
2023.01Production5
2023.01Production_Target7
2023.01Compliance8
2023.01Compliance_Target8
2023.02Production10
2023.02Production_Target12
2023.02Compliance4
2023.02Compliance_Target6
2023.03Production15
2023.03Production_Target13
2023.03Compliance11
2023.03Compliance_Target12

 

Rows where the Type column has the value "_Target" indicate that they are rows with target values ​​for the respective Indicator Type (for example, the type "Production" is the actual production value for each month and the "Production-Target" is the expected value for each month). I want to create charts for each Type that show the actual value for each month and a goal line (which shows the "_Target" values ​​for each month), but I'm not able to turn this table into a better way.

My expected table result would be this:

Year_MonthTypeValueObjective
2023.01Production57
2023.02Production1012
2023.03Production1513
2023.01Compliance88
2023.02Compliance46
2023.03Compliance1112

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  Anonymous ,

     

    Here are the steps you can follow:

    1. In Power Query -- Add Column – Index Column – From 1.

    2. Create calculated column.

    Group =
    MINX(
        FILTER(ALL('Table'),'Table'[Year_Month]=EARLIER('Table'[Year_Month])),[Index])
    Type_Group =
    IF(
        CONTAINSSTRING('Table'[Type],"Production_Target")=TRUE()
        ||
        CONTAINSSTRING('Table'[Type],"Compliance_Target")=TRUE()
        ,0,1)
    Sum =
    SUMX(
        FILTER(ALL('Table'),
        'Table'[Index]<=EARLIER('Table'[Index])),[Type_Group])
    Rank =
    RANKX(
        FILTER(ALL('Table'),
        'Table'[Group]=EARLIER('Table'[Group])&&'Table'[Sum]=EARLIER('Table'[Sum])),[Index],,ASC)
    Objective =
    IF(
        [Rank]=
        MINX(
            FILTER(ALL('Table'),'Table'[Sum]=EARLIER('Table'[Sum])),[Rank]),
         SUMX(
             FILTER(ALL('Table'),
             'Table'[Sum]=EARLIER('Table'[Sum])&&'Table'[Rank]=
             MAXX(
                 FILTER(
                     ALL('Table'),'Table'[Sum]=EARLIER('Table'[Sum])),[Rank])),[Value]
    ))

    3. Create calculated table.

    Table 2 =
    var _table=FILTER('Table',[Rank]=1)
    return
    SUMMARIZE(
        _table,[Year_Month],[Type],[Value],[Objective])

    4. Result:

     

    Best Regards,

    Liu Yang

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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

     

    Here are the steps you can follow:

    1. In Power Query -- Add Column – Index Column – From 1.

    2. Create calculated column.

    Group =
    MINX(
        FILTER(ALL('Table'),'Table'[Year_Month]=EARLIER('Table'[Year_Month])),[Index])
    Type_Group =
    IF(
        CONTAINSSTRING('Table'[Type],"Production_Target")=TRUE()
        ||
        CONTAINSSTRING('Table'[Type],"Compliance_Target")=TRUE()
        ,0,1)
    Sum =
    SUMX(
        FILTER(ALL('Table'),
        'Table'[Index]<=EARLIER('Table'[Index])),[Type_Group])
    Rank =
    RANKX(
        FILTER(ALL('Table'),
        'Table'[Group]=EARLIER('Table'[Group])&&'Table'[Sum]=EARLIER('Table'[Sum])),[Index],,ASC)
    Objective =
    IF(
        [Rank]=
        MINX(
            FILTER(ALL('Table'),'Table'[Sum]=EARLIER('Table'[Sum])),[Rank]),
         SUMX(
             FILTER(ALL('Table'),
             'Table'[Sum]=EARLIER('Table'[Sum])&&'Table'[Rank]=
             MAXX(
                 FILTER(
                     ALL('Table'),'Table'[Sum]=EARLIER('Table'[Sum])),[Rank])),[Value]
    ))

    3. Create calculated table.

    Table 2 =
    var _table=FILTER('Table',[Rank]=1)
    return
    SUMMARIZE(
        _table,[Year_Month],[Type],[Value],[Objective])

    4. Result:

     

    Best Regards,

    Liu Yang

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