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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
MohammedAli
Frequent Visitor

Dates effective from and to

Hi,

 

My data is in the following format

Emp IDPay TypeEffective FromEffective ToAmount
100001Basic1/Jan/201931/Jul/20191000
100001Basic1/Aug/201931/Dec/20191500
100001HRA1/Jan/201931/Jul/2019100
100001HRA1/Aug/201931/Dec/2019150

 

I want to transform the data to 

Emp IDMonthYearBasicHRA
100001Jan20191000100
100001Feb20191000100
100001Mar20191000100
100001Apr20191000100
100001May20191000100
100001Jun20191000100
100001Jul20191000100
100001Aug20191500150
100001Sep20191500150
100001Oct20191500150
100001Nov20191500150
100001Dec20191500150

 

Reqeust you to please guide me in the correct direction.

 

Thanks in advance.

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @MohammedAli 

Capture10.JPG

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQAAkMlHSWnxOLMZCBtqO+VmKdvZGBoCeQYA3mlOTAeSK1SrA5WTY6l6UiaXFKT4ZpM0TV5BDkStAe7DnyWKMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Emp ID" = _t, #"Pay Type" = _t, #"Effective From" = _t, #"Effective To" = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Emp ID", Int64.Type}, {"Pay Type", type text}, {"Effective From", type date}, {"Effective To", type date}, {"Amount", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Pay Type"]), "Pay Type", "Amount"),
    #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Custom", each List.Dates([Effective From],Duration.Days([Effective To]-[Effective From])+1,#duration(1,0,0,0))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Select([Custom],each Date.Day(_)=1)),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "new date"}}),
    #"Inserted Year" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([new date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([new date]), type text),
    #"Extracted First Characters" = Table.TransformColumns(#"Inserted Month Name", {{"Month Name", each Text.Start(_, 3), type text}})
in
    #"Extracted First Characters"

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @MohammedAli 

Capture10.JPG

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQAAkMlHSWnxOLMZCBtqO+VmKdvZGBoCeQYA3mlOTAeSK1SrA5WTY6l6UiaXFKT4ZpM0TV5BDkStAe7DnyWKMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Emp ID" = _t, #"Pay Type" = _t, #"Effective From" = _t, #"Effective To" = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Emp ID", Int64.Type}, {"Pay Type", type text}, {"Effective From", type date}, {"Effective To", type date}, {"Amount", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Pay Type"]), "Pay Type", "Amount"),
    #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Custom", each List.Dates([Effective From],Duration.Days([Effective To]-[Effective From])+1,#duration(1,0,0,0))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Select([Custom],each Date.Day(_)=1)),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "new date"}}),
    #"Inserted Year" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([new date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([new date]), type text),
    #"Extracted First Characters" = Table.TransformColumns(#"Inserted Month Name", {{"Month Name", each Text.Start(_, 3), type text}})
in
    #"Extracted First Characters"

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@MohammedAli , refer if this can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

or this file

https://www.dropbox.com/s/fnq82ksdzk1lqs3/Target_allocation_daily.pbix?dl=0

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.