Forum Discussion

ajay-sformula's avatar
ajay-sformula
Regular Visitor
8 years ago
Solved

convert 2 rows into two columns with common value

Hi, I have the following table:   Person Id             S or C Type            Element Id               Value 00001                  S                            1                                ...
  • v-huizhn-msft's avatar
    v-huizhn-msft
    8 years ago

    Hi ajay-sformula,

    Each Person Id can have many "Element Ids", you just add a "Element Ids" in TableB, then lookup Cvalue based on "Element Ids" and "Person Id".

    1. Create TableA and TableB.

    TableA = SELECTCOLUMNS(FILTER(Test1,Test1[S or C Type]="S"),"Person Id",Test1[Person Id],"Element Id",Test1[Element Id],"S Value",Test1[Value])
    
    TableB = SELECTCOLUMNS(FILTER(Test1,Test1[S or C Type]="C"),"Person Id",Test1[Person Id],"Element Id",Test1[Element Id],"C value",Test1[Value])


    2. In TableA, create a calculated column using the formula and get expected result.

    C value = LOOKUPVALUE(TableB[C value],TableB[Person Id],TableA[Person Id],TableB[Element Id],TableA[Element Id])



    In addition, for second solution in Query Editor, please click both "S or C Type" and "Element Id"->Pivot column->value and don't aggregate, you will get right results.



    Best Regards,
    Angelia