Forum Discussion

shei7141's avatar
shei7141
Icon for Helper III rankHelper III
6 years ago
Solved

Dax new table with multiple columns

Hi, 

 

I have a table which has

Items, Yr2001, Yr2002, Yr2003....Yr2046

 

How can I create a new table which can return the following

 

Items (<<only unique values), Yrs, Value

x, 2001, 5

x, 2002,15

.

.

y,2046,1

y, 2001, 5

y, 2002,15

.

.

y,2046,1

 

Thanks in advance

A

  • Anonymous's avatar
    Anonymous
    6 years ago

    I don't know how to programatically find out how many columns are there in your "calculated table", but if it is a fixed number of columns and you want to convert the same to the "Target" format, You could try this although, it is a bad example, and I feel, if you post the source table, instead of the calculated table, we can try out something.

     

    Target = 
    VAR T1 = 
        ADDCOLUMNS(
            ALL('OriginalData'[Item],'OriginalData'[Year2001]),
            "Year",2001)
    VAR T2 = 
        ADDCOLUMNS(
            ALL('OriginalData'[Item],'OriginalData'[Year2002]),
            "Year",2002)
    VAR T3 = 
        ADDCOLUMNS(
            ALL('OriginalData'[Item],'OriginalData'[Year2003]),
            "Year",2003)
    RETURN
    UNION(T1,T2,T3)

9 Replies

  • shei7141 

     

    What is 5 and 15  ?
    What x 5 and y  ?

    Please elaborate? 

    x, 2001, 5

    x, 2002,15

    • shei7141's avatar
      shei7141
      Icon for Helper III rankHelper III

      thanks mate, thats value under each year (i.e. field in the original)

      for example

      Item, Yr2001,Yr2002,Yr2006

      x,5,15,1

      • Fowmy's avatar
        Fowmy
        Icon for Super User rankSuper User

        shei7141 
         
        Sorry not clear what you are trying to get, please provide some source data and give more clarity 

        Thanks