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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.