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
Hello mb0307
you can calculate such a text-field to use it then in the cube-function. Here a example. However, I didn't understand which time frame you want to calculate. But if you check out the approach, you should have an idea how to continue
let
FristDayOfThisMonth = Date.From(DateTime.FixedLocalNow()),
Year = Text.From(Date.Year(FristDayOfThisMonth)),
Month = "0"&Text.From(Date.Month(FristDayOfThisMonth)),
Day = "0"&Text.From(Date.Day(FristDayOfThisMonth)),
CreateTextForQuery = "[0DSDEL_DATE].["&Year&Text.End(Month,2)&Text.End(Day,2)&"]"
in
CreateTextForQuery
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
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.
- Jimmy8015 years agoCommunity Champion
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