A
- AccessControlEntry.ConditionToIdentities
- Access.Database
- ActiveDirectory.Domains
- AdobeAnalytics.Cubes
- AdoDotNet.DataSource
- AdoDotNet.Query
- AnalysisServices.Database
- AnalysisServices.Databases
- AzureStorage.BlobContents
- AzureStorage.Blobs
- AzureStorage.DataLake
- AzureStorage.DataLakeContents
- AzureStorage.Tables
B
- BinaryFormat.Binary
- BinaryFormat.Byte
- BinaryFormat.ByteOrder
- BinaryFormat.Choice
- BinaryFormat.Decimal
- BinaryFormat.Double
- BinaryFormat.Group
- BinaryFormat.Length
- BinaryFormat.List
- BinaryFormat.Null
- BinaryFormat.Record
- BinaryFormat.SignedInteger16
- BinaryFormat.SignedInteger32
- BinaryFormat.SignedInteger64
- BinaryFormat.Single
- BinaryFormat.Text
- BinaryFormat.Transform
- BinaryFormat.UnsignedInteger16
- BinaryFormat.UnsignedInteger32
- BinaryFormat.UnsignedInteger64
- BinaryFormat.7BitEncodedSignedInteger
- BinaryFormat.7BitEncodedUnsignedInteger
- Binary data
- Binary.ApproximateLength
- Binary.Buffer
- Binary.Combine
- Binary.Compress
- Binary.Decompress
- Binary.From
- Binary.FromList
- Binary.FromText
- Binary.InferContentType
- Binary.Length
- Binary.Range
- Binary.Split
- Binary.ToList
- Binary.ToText
- Binary.View
- Binary.ViewError
- Binary.ViewFunction
- Byte.From
C
- Cdm.Contents
- Character.FromNumber
- Character.ToNumber
- Combiner.CombineTextByDelimiter
- Combiner.CombineTextByEachDelimiter
- Combiner.CombineTextByLengths
- Combiner.CombineTextByPositions
- Combiner.CombineTextByRanges
- Comparer.FromCulture
- Comparer.Ordinal
- Comparer.OrdinalIgnoreCase
- Controlling byte order
- Csv.Document
- Cube.AddAndExpandDimensionColumn
- Cube.AddMeasureColumn
- Cube.ApplyParameter
- Cube.AttributeMemberId
- Cube.AttributeMemberProperty
- Cube.CollapseAndRemoveColumns
- Cube.Dimensions
- Cube.DisplayFolders
- Cube.MeasureProperties
- Cube.MeasureProperty
- Cube.Measures
- Cube.Parameters
- Cube.Properties
- Cube.PropertyKey
- Cube.ReplaceDimensions
- Cube.Transform
- Currency.From
D
- DateTime.AddZone
- DateTime.Date
- DateTime.FixedLocalNow
- DateTime.From
- DateTime.FromFileTime
- DateTime.FromText
- DateTime.IsInCurrentHour
- DateTime.IsInCurrentMinute
- DateTime.IsInCurrentSecond
- DateTime.IsInNextHour
- DateTime.IsInNextMinute
- DateTime.IsInNextNHours
- DateTime.IsInNextNMinutes
- DateTime.IsInNextNSeconds
- DateTime.IsInNextSecond
- DateTime.IsInPreviousHour
- DateTime.IsInPreviousMinute
- DateTime.IsInPreviousNHours
- DateTime.IsInPreviousNMinutes
- DateTime.IsInPreviousNSeconds
- DateTime.IsInPreviousSecond
- DateTime.LocalNow
- DateTime.Time
- DateTime.ToRecord
- DateTime.ToText
- Date.AddDays
- Date.AddMonths
- Date.AddQuarters
- Date.AddWeeks
- Date.AddYears
- Date.Day
- Date.DayOfWeek
- Date.DayOfWeekName
- Date.DayOfYear
- Date.DaysInMonth
- Date.EndOfDay
- Date.EndOfMonth
- Date.EndOfQuarter
- Date.EndOfWeek
- Date.EndOfYear
- Date.From
- Date.FromText
- Date.IsInCurrentDay
- Date.IsInCurrentMonth
- Date.IsInCurrentQuarter
- Date.IsInCurrentWeek
- Date.IsInCurrentYear
- Date.IsInNextDay
- Date.IsInNextMonth
- Date.IsInNextNDays
- Date.IsInNextNMonths
- Date.IsInNextNQuarters
- Date.IsInNextNWeeks
- Date.IsInNextNYears
- Date.IsInNextQuarter
- Date.IsInNextWeek
- Date.IsInNextYear
- Date.IsInPreviousDay
- Date.IsInPreviousMonth
- Date.IsInPreviousNDays
- Date.IsInPreviousNMonths
- Date.IsInPreviousNQuarters
- Date.IsInPreviousNWeeks
- Date.IsInPreviousNYears
- Date.IsInPreviousQuarter
- Date.IsInPreviousWeek
- Date.IsInPreviousYear
- Date.IsInYearToDate
- Date.IsLeapYear
- Date.Month
- Date.MonthName
- Date.QuarterOfYear
- Date.StartOfDay
- Date.StartOfMonth
- Date.StartOfQuarter
- Date.StartOfWeek
- Date.StartOfYear
- Date.ToRecord
- Date.ToText
- Date.WeekOfMonth
- Date.WeekOfYear
- Date.Year
- DB2.Database
- Decimal.From
- Diagnostics.ActivityId
- Diagnostics.Trace
- DirectQueryCapabilities.From
- Double.From
- Duration.Days
- Duration.From
- Duration.FromText
- Duration.Hours
- Duration.Minutes
- Duration.Seconds
- Duration.ToRecord
- Duration.TotalDays
- Duration.TotalHours
- Duration.TotalMinutes
- Duration.TotalSeconds
- Duration.ToText
E
F
G
H
I
L
- Lines.FromBinary
- Lines.FromText
- Lines.ToBinary
- Lines.ToText
- List.Accumulate
- List.AllTrue
- List.Alternate
- List.AnyTrue
- List.Average
- List.Buffer
- List.Combine
- List.ConformToPageReader
- List.Contains
- List.ContainsAll
- List.ContainsAny
- List.Count
- List.Covariance
- List.Dates
- List.DateTimes
- List.DateTimeZones
- List.Difference
- List.Distinct
- List.Durations
- List.FindText
- List.First
- List.FirstN
- List.Generate
- List.InsertRange
- List.Intersect
- List.IsDistinct
- List.IsEmpty
- List.Last
- List.LastN
- List.MatchesAll
- List.MatchesAny
- List.Max
- List.MaxN
- List.Median
- List.Min
- List.MinN
- List.Mode
- List.Modes
- List.NonNullCount
- List.Numbers
- List.Percentile
- List.PositionOf
- List.PositionOfAny
- List.Positions
- List.Product
- List.Random
- List.Range
- List.RemoveFirstN
- List.RemoveItems
- List.RemoveLastN
- List.RemoveMatchingItems
- List.RemoveNulls
- List.RemoveRange
- List.Repeat
- List.ReplaceMatchingItems
- List.ReplaceRange
- List.ReplaceValue
- List.Reverse
- List.Select
- List.Single
- List.SingleOrDefault
- List.Skip
- List.Sort
- List.Split
- List.StandardDeviation
- List.Sum
- List.Times
- List.Transform
- List.TransformMany
- List.Union
- List.Zip
- Logical.From
- Logical.FromText
What is Date.IsInNextNWeeks?
The Date.IsInNextNWeeks function is used to determine if a date falls within a certain number of weeks from the current date. It takes two arguments: the date to be tested, and the number of weeks from the current date. If the date falls within the specified number of weeks, the function returns true, otherwise it returns false.
The M Code Behind Date.IsInNextNWeeks
The M code behind the Date.IsInNextNWeeks function is relatively simple. Here is the code:
let
IsInNextNWeeks = (date as date, numberOfWeeks as number) as logical =>
let
currentDate = Date.From(DateTime.LocalNow()),
endDate = Date.AddDays(currentDate, numberOfWeeks 7)
in
date <= endDate
in
IsInNextNWeeks
The code defines a function called IsInNextNWeeks that takes two arguments: the date to be tested and the number of weeks from the current date. The function returns a logical value indicating whether the date falls within the specified number of weeks.
The function first gets the current date using the DateTime.LocalNow() function, which returns the current date and time in the local time zone. The Date.From function is then used to extract the date from the current date and store it in a variable called currentDate.
Next, the function calculates the end date by adding the specified number of weeks to the current date using the Date.AddDays function. The result is stored in a variable called endDate.
Finally, the function checks whether the date to be tested is less than or equal to the end date. If it is, the function returns true, indicating that the date falls within the specified number of weeks. If it is not, the function returns false.
Using Date.IsInNextNWeeks
The Date.IsInNextNWeeks function can be used in a variety of ways to simplify data transformation tasks. Here are some examples:
Example 1: Filtering Data
Suppose you have a table of sales data that includes a column called OrderDate. You want to filter the table to include only the sales that occurred within the next two weeks. Here's how you can do it using the Date.IsInNextNWeeks function:
let
Source = Table.FromRecords({
[OrderDate = #date(2022, 3, 1)],
[OrderDate = #date(2022, 3, 7)],
[OrderDate = #date(2022, 3, 14)],
[OrderDate = #date(2022, 3, 21)]
}),
FilteredRows = Table.SelectRows(Source, each Date.IsInNextNWeeks([OrderDate], 2))
in
FilteredRows
The code creates a table with four rows, each representing a different order date. The Table.SelectRows function is then used to filter the table to include only the rows where the OrderDate falls within the next two weeks. The Date.IsInNextNWeeks function is used as the filter function, with the OrderDate column passed as the first argument and the number 2 passed as the second argument.
The resulting table includes only the rows where the OrderDate falls within the next two weeks.
Example 2: Calculating Rolling Averages
Suppose you have a table of sales data that includes a column called SalesDate and a column called SalesAmount. You want to calculate the rolling average of sales over the next four weeks for each SalesDate. Here's how you can do it using the Date.IsInNextNWeeks function:
let
Source = Table.FromRecords({
[SalesDate = #date(2022, 3, 1), SalesAmount = 100],
[SalesDate = #date(2022, 3, 7), SalesAmount = 200],
[SalesDate = #date(2022, 3, 14), SalesAmount = 300],
[SalesDate = #date(2022, 3, 21), SalesAmount = 400]
}),
GroupedRows = Table.Group(Source, “SalesDate”, “GroupedData”, (group) =>
let
SortedRows = Table.Sort(group, {{“SalesDate”, Order.Ascending}}),
RollingAverage = Table.AddColumn(SortedRows, “RollingAverage”,
each List.Average(
Table.SelectRows(SortedRows,
each Date.IsInNextNWeeks([SalesDate], 4) and [SalesDate] <= [SalesDate] )),
type number)
in
RollingAverage
)
in
GroupedRows
The code creates a table with four rows, each representing a different sales date and sales amount. The Table.Group function is then used to group the rows by SalesDate and calculate the rolling average of sales over the next four weeks for each SalesDate.
The Date.IsInNextNWeeks function is used to select the rows that fall within the next four weeks for each SalesDate. The List.Average function is then used to calculate the average of the SalesAmount column for those rows. The resulting table includes a new column called RollingAverage, which contains the rolling average of sales over the next four weeks for each SalesDate.
The Date.IsInNextNWeeks function is a powerful tool for simplifying data transformation tasks in Power Query M. By understanding the M code behind this function and learning how to use it effectively, you can streamline your data transformation workflows and save time and effort.