Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
shei7141
Helper III
Helper III

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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)

View solution in original post

9 REPLIES 9
Fowmy
Super User
Super User

@shei7141 

 

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

Please elaborate? 

x, 2001, 5

x, 2002,15

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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

for example

Item, Yr2001,Yr2002,Yr2006

x,5,15,1

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

Thanks

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

sorry for confusing the situation. I hope the following data sample will provide some clarity

 

Original > data  
    
ItemYear2001Year2002Year2003
x15105
y11520
z153040

 

Target   
   
ItemYearValue
x200115
y200210
z20035
x20011
y200215
z200320
x200115
y200230
z200340

@shei7141 

 

You can do in Power Query using UnPivot.

Select Item Column and right-click, select UnPivot Other Columns
Select Year Column and select Replace Value, to enter Year and blank.
Done

Watch This video: https://www.youtube.com/watch?v=Vff2kRBM95o


If you are satisfied with my answer, please mark it as a solution so others can easily find it.

Don't forget to give KUDOS  to replies that help answer your questions


Subscribe to ExcelFort: Learn Power BI, Power Query and Excel


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

thanks heaps mate

 

My table is a calculated table and I am unable to accesss the edit query interface,

Anonymous
Not applicable

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)

Thank you both for your time and assistance - really appreciate it 

you guys are legend 🙂

@shei7141 

Please share a sample PBI file with source or sample data.

Thanks

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.