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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

keepind dates as column headers

Hi,

 

I have date in excel where my dates aare my column headers- ed, Apr-20, MAy-20, etc. Now when I import my data in Power BI the headers are changed to text. But I need them to stay in date format as I need to show the change of month over month .

 

Pls help!

sgs_0-1600181609532.png

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

in your case your headers in Excel are stored as date (01/01/2020) but visualized in another format like Apr-20. As Power BI is reading the real data in the cells, not the visualisation. So, or you transform your data in Excel like real text or you apply something like that

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDRNzDUNzIwMlDSUTIwReaYwTmxOtFKhkAhIyA2VoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    TransformFirstRow = Table.FromRecords( Table.TransformRows
    (
        #"Added Index",
        (rec)=> if rec[Index]=0 then Record.FromTable(Table.TransformColumns(Record.ToTable(rec), {{"Value", each Date.ToText(Date.From(_,"en-US"),"MMM-YY","en-US")}})) else rec
    )),
    #"Removed Columns" = Table.RemoveColumns(TransformFirstRow,{"Index"}),
    PromoteHeader = Table.PromoteHeaders(#"Removed Columns")
in
    PromoteHeader

 

Excel-import

Jimmy801_0-1600193781934.png

after transformation

Jimmy801_1-1600193802175.png

 

I've simulate the source-step as if you would access to your Excel-sheet

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

in your case your headers in Excel are stored as date (01/01/2020) but visualized in another format like Apr-20. As Power BI is reading the real data in the cells, not the visualisation. So, or you transform your data in Excel like real text or you apply something like that

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDRNzDUNzIwMlDSUTIwReaYwTmxOtFKhkAhIyA2VoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    TransformFirstRow = Table.FromRecords( Table.TransformRows
    (
        #"Added Index",
        (rec)=> if rec[Index]=0 then Record.FromTable(Table.TransformColumns(Record.ToTable(rec), {{"Value", each Date.ToText(Date.From(_,"en-US"),"MMM-YY","en-US")}})) else rec
    )),
    #"Removed Columns" = Table.RemoveColumns(TransformFirstRow,{"Index"}),
    PromoteHeader = Table.PromoteHeaders(#"Removed Columns")
in
    PromoteHeader

 

Excel-import

Jimmy801_0-1600193781934.png

after transformation

Jimmy801_1-1600193802175.png

 

I've simulate the source-step as if you would access to your Excel-sheet

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Greg_Deckler
Super User
Super User

@Anonymous Can you just rename them? Otherwise, before your promoted headers step try transforming the data to text. Or possibly edit the Change Type step? Would have to see your Advaned Editor code.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors