Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
In this article, we will look at how to solve an allocation issue where you need to deal with start and end dates falling within different dates in months.
For Con-01 in the table below, the amount of 110,000 has to be divided by 291 days and multiplied by 22 days in Jan-2020, 29 days in Feb-2020, and so on, Oct-2020 will have 26 days. looks pretty simple?
The challenge is that any addition of new contracts or changes in contract periods should automatically adjust the number of rows and columns, in the meantime calculating the monthly amounts correctly as explained above.
The Pivot Table below shows the desired result that we are trying to achieve here. It is giving the flexibility to analyze the above contracts in various date dimensions, even with a large number of records.
Power Query Steps:
(pStart as date, pEnd as date) => let
Source = List.Generate(
()=> [fDate = pStart, fDay= Date.DaysInMonth(fDate)-Date.Day(fDate)+1],
each [fDate] <= pEnd,
each
let EoM = Date.EndOfMonth( Date.AddMonths([fDate],1)) in
if EoM > pEnd then
[fDate= Date.AddDays(Date.EndOfMonth([fDate]), Date.Day(pEnd)) , fDay= Date.Day(fDate)]
else
[fDate= EoM , fDay = Date.Day(fDate)]
),
ToTable = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ExpandTable = Table.ExpandRecordColumn(ToTable, "Column1", {"fDate", "fDay"}, {"fDate", "fDay"}),
ChangedType = Table.TransformColumnTypes(ExpandTable,{{"fDate", type date}, {"fDay", Int64.Type}})
in
ChangedType
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.