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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
harshadrokade
Post Partisan
Post Partisan

Table with variable colum headers

Hi,

 

I have below data. I want to create a table visual as shown further. I want to show only latest three year data in the power bi table. To add he data in table, I had to unpivot the original table but then it makes it difficult to get only latest three years data in the table. Can u pls help me to create a power bi table which will look same as shown at the bottom & will keep changing the years in the colum header for latest three years.

 

Original table-

Student nameYearSubject1Subject2Subject3Subject4Subject5Subject6
A12015565731
A12016765526
A12017183597
A12018592317
A12019379536
A12020213175
A22015293489
A22016369164
A22017316842
A22018351168
A22019459274
A22020153278
A32015684656
A32016547986
A32017767263
A32018386493
A32019927955
A32020761726

 

Expected Power bi Table with Student name slicer-

(Selected Student A1 in slicer)

Subject202020192018
Subject1235
Subject2179
Subject3392
Subject4153
Subject5731
Subject6567

 

2 ACCEPTED SOLUTIONS
TomMartens
Super User
Super User

Hey @harshadrokade 

you can this code snippet in Power Query

//the latest year will be determined
    maxyear = List.Max( #"Changed Type"[Year] ),
    
    // the latest year will be used to filter the rows ... > maxyear -2 
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Year] >= maxyear - 2),

    //all the other columns will be unpivoted Subject1 ... Subjectn
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Student name", "Year"}, "Attribute", "Value")

 This will provide a table that looks like this:
image.png
Hopefully, this provides what you are looking for.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1645501564523.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1645501564523.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

TomMartens
Super User
Super User

Hey @harshadrokade 

you can this code snippet in Power Query

//the latest year will be determined
    maxyear = List.Max( #"Changed Type"[Year] ),
    
    // the latest year will be used to filter the rows ... > maxyear -2 
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Year] >= maxyear - 2),

    //all the other columns will be unpivoted Subject1 ... Subjectn
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Student name", "Year"}, "Attribute", "Value")

 This will provide a table that looks like this:
image.png
Hopefully, this provides what you are looking for.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.