Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Data Reshaping ( multiple assignment to single assignment)

Hello! 🙂
I do have a table with (amongst other columns) the following data:

NameField1Field2Field3Field4Field5
abcA1A1E3S2Q1
abcS2FrA1U1I1
..................
defA2D3 F3S2
defC2A4F3  
..................

Notes:
There are more then two names

Field 1-5 are next to each other, "Name" is further away

Field1-5 only includes one value per cell which consists of a number and a letter

I try to get/need:

T1:

NameField
abcA1
abcA1
... 
defA2
 D3
......


and

T2:

NameFieldCount
abcA13
.........
defF32
.........


Verbally spoken: I need a 1:1 assigment of name:field and also, how often a certain field occurs, regardless the Field (1-5) and the row of T1, only in dependence of the name  (so for example A1 occurs in T1 in row 1 (abc) 2x, in row 2 (abc) 1x -> abc A1 3
I only have Power BI as tool aviable and I am completly new to it. So it would be lovely, if someone could help me out! 🙂

  • Hi, Anonymous 

    You can create a Calculated column and a Measure to get the tables you want.

     

    Calculated column :

     

     

    Name_Field =

    VAR t1 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field1] )

    VAR t2 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field2] )

    VAR t3 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field3] )

    VAR t4 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field4] )

    VAR t5 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field5] )

    VAR union_t =

        UNION ( t1, t2, t3, t4, t5 )

    VAR tt =

        FILTER ( union_t, AND ( [Field] <> "", NOT ( ISBLANK ( [Field] ) ) ) )

    RETURN

        tt

     

     

    Measure :

     

     

    Count = COUNTX('Name_Field','Name_Field'[Field])

     

    The result looks like this:

    Here is the pbix file.

     

    Best Regards,

    Caiyun Zheng

     

    Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

3 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello amitchandak 
      Thank you for your reply. The data is not pivoted from the beginning on, the base table is just a flat data structure. Do you know how I can work with your solution then?

  • v-cazheng-msft's avatar
    v-cazheng-msft
    Community Support

    Hi, Anonymous 

    You can create a Calculated column and a Measure to get the tables you want.

     

    Calculated column :

     

     

    Name_Field =

    VAR t1 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field1] )

    VAR t2 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field2] )

    VAR t3 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field3] )

    VAR t4 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field4] )

    VAR t5 =

        SELECTCOLUMNS ( 'Table', "Name", 'Table'[Name], "Field", 'Table'[Field5] )

    VAR union_t =

        UNION ( t1, t2, t3, t4, t5 )

    VAR tt =

        FILTER ( union_t, AND ( [Field] <> "", NOT ( ISBLANK ( [Field] ) ) ) )

    RETURN

        tt

     

     

    Measure :

     

     

    Count = COUNTX('Name_Field','Name_Field'[Field])

     

    The result looks like this:

    Here is the pbix file.

     

    Best Regards,

    Caiyun Zheng

     

    Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.