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.
Hello,
A few months ago someone helpfully provided me with the M query below. This was designed to expand a table to include a row per month of activity between the designated dates. I have adapted the query below, but for some reason, the first month of absence is not included. Can anyone fix the query or suggest an alternative solution?
(#"Absence Start Date" as date, #"Absence End Date" as date ) => let enddate = if #"Absence End Date" = null then DateTime.Date( DateTime.LocalNow() ) else #"Absence End Date", days = Duration.Days( enddate - #"Absence Start Date" ), listDates = List.Dates( #"Absence Start Date", days, #duration( 1, 0, 0, 0 ) ), firstDates = List.Select( listDates, each Date.Day( _ ) = 1 ), monthYear = List.Transform( firstDates, each Text.Start( Date.MonthName( _ ), 3 ) & "- " & Text.End( Number.ToText( Date.Year( _ ) ), 2 ) ) in monthYear
Tiff
Solved! Go to Solution.
Hi @Anonymous
It looks like my work , please see the adjusted function below.
(#"Absence Start Date" as date, #"Absence End Date" as date ) => let enddate = if #"Absence End Date" = null then DateTime.Date( DateTime.LocalNow() ) else #"Absence End Date", days = Duration.Days( enddate - #"Absence Start Date" ) + 1, listDates = List.Dates( #"Absence Start Date", days, #duration( 1, 0, 0, 0 ) ), monthYear = List.Transform( listDates, each Text.Start( Date.MonthName( _ ), 3 ) & "- " & Text.End( Number.ToText( Date.Year( _ ) ), 2 ) ), distMonthYear = List.Distinct( monthYear ) in distMonthYear
Hi @Anonymous
It looks like my work , please see the adjusted function below.
(#"Absence Start Date" as date, #"Absence End Date" as date ) => let enddate = if #"Absence End Date" = null then DateTime.Date( DateTime.LocalNow() ) else #"Absence End Date", days = Duration.Days( enddate - #"Absence Start Date" ) + 1, listDates = List.Dates( #"Absence Start Date", days, #duration( 1, 0, 0, 0 ) ), monthYear = List.Transform( listDates, each Text.Start( Date.MonthName( _ ), 3 ) & "- " & Text.End( Number.ToText( Date.Year( _ ) ), 2 ) ), distMonthYear = List.Distinct( monthYear ) in distMonthYear
That's worked perfectly, thanks so much for your help then and now!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
85 | |
67 | |
59 |
User | Count |
---|---|
150 | |
120 | |
99 | |
87 | |
68 |