Forum Discussion
Last 6 months data
- 5 years ago
Hello mb0307
here a code that creates two variables (CreateTextForQueryEnd and CreateTextForQueryStart) that you can use in your code
let Today = Date.From(DateTime.FixedLocalNow()), YearToday = Text.From(Date.Year(Today)), MonthToday = "0"&Text.From(Date.Month(Today)), DayToday = "0"&Text.From(Date.Day(Today)), CreateTextForQueryEnd = "[0DSDEL_DATE].["&YearToday&Text.End(MonthToday,2)&Text.End(DayToday,2)&"]", Minus6MonthsFirstDayOfMonth = Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.FixedLocalNow()),-6)), Year6Months = Text.From(Date.Year(Minus6MonthsFirstDayOfMonth)), Month6Months = "0"&Text.From(Date.Month(Minus6MonthsFirstDayOfMonth)), Day6Months = "0"&Text.From(Date.Day(Minus6MonthsFirstDayOfMonth)), CreateTextForQueryStart = "[0DSDEL_DATE].["&Year6Months&Text.End(Month6Months,2)&Text.End(Day6Months,2)&"]" in CreateTextForQueryStartCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Jimmy801 Thanks for your response and apologies if my query wasn't clear. I have edited my post with an example. Your code doesn't go back 6 months and start from 1st of the oldest month.
Hello mb0307
here a code that creates two variables (CreateTextForQueryEnd and CreateTextForQueryStart) that you can use in your code
let
Today = Date.From(DateTime.FixedLocalNow()),
YearToday = Text.From(Date.Year(Today)),
MonthToday = "0"&Text.From(Date.Month(Today)),
DayToday = "0"&Text.From(Date.Day(Today)),
CreateTextForQueryEnd = "[0DSDEL_DATE].["&YearToday&Text.End(MonthToday,2)&Text.End(DayToday,2)&"]",
Minus6MonthsFirstDayOfMonth = Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.FixedLocalNow()),-6)),
Year6Months = Text.From(Date.Year(Minus6MonthsFirstDayOfMonth)),
Month6Months = "0"&Text.From(Date.Month(Minus6MonthsFirstDayOfMonth)),
Day6Months = "0"&Text.From(Date.Day(Minus6MonthsFirstDayOfMonth)),
CreateTextForQueryStart = "[0DSDEL_DATE].["&Year6Months&Text.End(Month6Months,2)&Text.End(Day6Months,2)&"]"
in
CreateTextForQueryStart
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy