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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lkarolak
Frequent Visitor

Splitting period data into months

Hello,

I have my data in the following structure:

 

ID        BEGIN           END                       VALUE

1         01.10.2017   31.12.2017              90

2         01.01.2016   31.10.2017              1000

....

 

I need to present this data on a time axis, so that I see the values overlapping and summing up for each month.

 

Now, I would like to either split the data into more rows, so that the period (Begin-End) will be splitted into single months. E.g. for first row (see above), I would have months: October 2017, November 2017, December 2017. And for each of these rows the original value would be divided by the number of the rows, in this case it would be 90/3=30.

 

Another approach would be to use the current data structure, but I don't know how to present such time periods (from-until) on a chart. Is it possible at all?

 

Thank you in advance for your suggestions!

 

Another approach

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

Hi @lkarolak,

 

In your scenario, you can create a function use a blank query like below:

 

(startdate as date, enddate as date) as table =>
let
 //startdate=#date(2015,8,1),
 //enddate=#date(2016,1,31),
 Source = {Number.From(startdate)..Number.From(enddate)},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),
    #"Calculated End of Month" = Table.TransformColumns(#"Renamed Columns",{{"Date", Date.EndOfMonth, type date}}),
    #"Removed Duplicates" = Table.Distinct(#"Calculated End of Month"),
    #"Inserted End of Year" = Table.AddColumn(#"Removed Duplicates", "EndOfYear", each Date.EndOfYear([Date]), type date),
    #"Grouped Rows" = Table.Group(#"Inserted End of Year", {}, {{"Original", each _, type table}, {"Months_Total", each Table.RowCount(_), type number}})
in
    #"Grouped Rows"

 Then rename the function as fnGetAllocationBase.

 

 

In the query which get the fact table, invoke this function like below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDTXNTTQRbCNdI1BHEsDpVidaCUjiLiZrqEusnKwEkMDA6CiWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, BEGIN = _t, END = _t, VALUE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"BEGIN", type date}, {"END", type date}, {"VALUE", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each fnGetAllocationBase([BEGIN],[END])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"BEGIN", "END"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Original", "Months_Total"}, {"Custom.Original", "Custom.Months_Total"}),
    #"Expanded Custom.Original" = Table.ExpandTableColumn(#"Expanded Custom", "Custom.Original", {"Date", "EndOfYear"}, {"Custom.Original.Date", "Custom.Original.EndOfYear"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom.Original", "Value_update", each [VALUE]/[Custom.Months_Total]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom.Original.Date", type date}, {"Custom.Original.EndOfYear", type date}})
in
    #"Changed Type1"

 

 

q4.PNG

 

 

Reference:

Allocate Units Based on Dates Using Power Query

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
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

5 REPLIES 5
v-qiuyu-msft
Community Support
Community Support

Hi @lkarolak,

 

In your scenario, you can create a function use a blank query like below:

 

(startdate as date, enddate as date) as table =>
let
 //startdate=#date(2015,8,1),
 //enddate=#date(2016,1,31),
 Source = {Number.From(startdate)..Number.From(enddate)},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),
    #"Calculated End of Month" = Table.TransformColumns(#"Renamed Columns",{{"Date", Date.EndOfMonth, type date}}),
    #"Removed Duplicates" = Table.Distinct(#"Calculated End of Month"),
    #"Inserted End of Year" = Table.AddColumn(#"Removed Duplicates", "EndOfYear", each Date.EndOfYear([Date]), type date),
    #"Grouped Rows" = Table.Group(#"Inserted End of Year", {}, {{"Original", each _, type table}, {"Months_Total", each Table.RowCount(_), type number}})
in
    #"Grouped Rows"

 Then rename the function as fnGetAllocationBase.

 

 

In the query which get the fact table, invoke this function like below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDTXNTTQRbCNdI1BHEsDpVidaCUjiLiZrqEusnKwEkMDA6CiWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, BEGIN = _t, END = _t, VALUE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"BEGIN", type date}, {"END", type date}, {"VALUE", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each fnGetAllocationBase([BEGIN],[END])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"BEGIN", "END"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Original", "Months_Total"}, {"Custom.Original", "Custom.Months_Total"}),
    #"Expanded Custom.Original" = Table.ExpandTableColumn(#"Expanded Custom", "Custom.Original", {"Date", "EndOfYear"}, {"Custom.Original.Date", "Custom.Original.EndOfYear"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom.Original", "Value_update", each [VALUE]/[Custom.Months_Total]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom.Original.Date", type date}, {"Custom.Original.EndOfYear", type date}})
in
    #"Changed Type1"

 

 

q4.PNG

 

 

Reference:

Allocate Units Based on Dates Using Power Query

 

Best Regards,
Qiuyun Yu

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

@v-qiuyu-msft 

 

Great solution!

 

I tried to use your solution to split total contract value (TCV) into annual contract value (ACV) but with no luck.

My data has a mixture of contracts duration between 1 day to 5years+

All contracts =< 1 year require no attention but if a contract is eg 4 year long, it should be split into 4 rows as follows. Here is the example:

 

Source:

Index   AmountStart Date      End Date            YearDays
1   261,600.0001/06/201631/12/201920161308

 

Result:

Index   AmountStart Date      End Date            YearDays
1     72,800.0001/06/201631/05/20172016364
1     72,800.0001/06/201731/05/20182017364
1     72,800.0001/06/201831/05/20192018364
1     42,600.0001/06/201931/12/20192019213

 

So i need to include full 12 months (72,800 USD)  into 2016 as ACV (as opposed to revenue recognition method where i would include only 7 months) ..

 

Hope it is clear and someone can help! 🙂

awesome! exactly what I needed! thanks so much

Anonymous
Not applicable

@v-qiuyu-msft

Wow, this is an AWESOME solution!

It helped me very much, thank you Qiuyun!

 

Please tell me, where can I learn more of those tricks and advanced scenarios working with Power Query.

I mean manipulating tables / using functions, etc.

Would you recommend some site / book / youtube?

 

Thanks

Michael

Thanks Qiuyun Yu, that seems to do the trick!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.