For some reason, my dates table is not working. I have tried to troubleshoot without success. The file is attached. Amy thoughts?Pipedrive Deals.pbix (435.0 KB)
your date table is 2014-2016, but your data is form 2019-2020
Use Deals[Deal created] instead of Dates[Date] in your visual.
Thank you, Heather!
You are quite welcome @jmolina
at some point, you may want to consider a date table that lets you make use of the max and min dates in your dataset.
Do you have the code for that? I can easily switch them out.
My code actually handles the dates outside of the calendar table - feeds them in as parameters.
so, build a blank query - and type this into the bar (modify for your dataset) to grab the Max date:
= Date.Day(List.Max(USAGE[Posting Date])
call this query âEndDateâ
Next, build a blank query and type this into the bar:
= Date.AddYears (Date.StartOfYear (EndDate), -2)
call this query âStartDateâ (you could also modify to use List.Min if you like)
Iâll plug the calendar into the next reply
@Heather do you have the code for that table?
Calendar Table code:
let
#"==Build Date Column==" =CurrentDate,
ListDates = List.Dates(StartDate, Number.From(EndDate - StartDate)+1, #duration(1,0,0,0)),
#âConverted to Tableâ = Table.FromList(ListDates, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#âRenamed Columns as Dateâ = Table.RenameColumns(#âConverted to Tableâ,{{âColumn1â, âDateâ}}),
// As far as Power BI is concerned, the âDateâ column is all that is needed But we will continue and add a few Human-Friendly Columns
#âChanged Type to Dateâ = Table.TransformColumnTypes(#âRenamed Columns as Dateâ,{{âDateâ, type date}}),
#"==Add Calendar Columns==" = #âChanged Type to Dateâ,
#âAdded Calendar MonthNumâ = Table.AddColumn(#"==Add Calendar Columns==", âMonthNumâ, each Date.Month([Date]), Int64.Type),
#âAdded Month Name Longâ = Table.AddColumn(#âAdded Calendar MonthNumâ, âMonthLongâ, each Date.MonthName([Date]), type text),
#âAdded Monthâ = Table.AddColumn(#âAdded Month Name Longâ, âMonthâ, each Text.Start([MonthLong], 3), type text),
#âAdded Calendar Quarterâ = Table.AddColumn(#âAdded Monthâ, âQuarterâ, each âQâ & Text.From(Date.QuarterOfYear([Date]))),
#âAdded QtrNumâ = Table.AddColumn(#âAdded Calendar Quarterâ, âQtrNumâ, each Date.QuarterOfYear([Date])),
#âAdded Calendar Yearâ = Table.AddColumn(#âAdded QtrNumâ, âYearâ, each Date.Year([Date]), Int64.Type),
#"==Add Calendar Date Offset Columns==" = #âAdded Calendar Yearâ,
// Can be used to for example to show the past 3 months(CurMonthOffset = 0, -1, -2)
#âAdded CurMonthOffsetâ = Table.AddColumn(#"==Add Calendar Date Offset Columns==", âCurMonthOffsetâ, each ( Date.Year([Date]) - Date.Year(CurrentDate) ) * 12+ Date.Month([Date]) - Date.Month(CurrentDate), Int64.Type),
// Can be used to for example to show the past 3 quarters (CurQuarterOffset = 0, -1, -2)
#âAdded CurQuarterOffsetâ = Table.AddColumn(#âAdded CurMonthOffsetâ, âCurQuarterOffsetâ, each /Year Difference/
( Date.Year([Date]) - Date.Year(CurrentDate) )*4
/Quarter Difference/
+ Number.RoundUp(Date.Month([Date]) / 3)
- Number.RoundUp(Date.Month(CurrentDate) / 3),
Int64.Type),
// Can be used to for example to show the past 3 years (CurYearOffset = 0, -1, -2)
#âAdded CurYearOffsetâ = Table.AddColumn(#âAdded CurQuarterOffsetâ, âCurYearOffsetâ, each Date.Year([Date]) - Date.Year(CurrentDate), Int64.Type),
#"==Add General Columns==" = #âAdded CurYearOffsetâ,
// Used as âSort by Columnâ for MonthYear columns
#âAdded MonthYearNumâ = Table.AddColumn(#"==Add General Columns==", âMonthYearNumâ, each [Year]*100 + [MonthNum] /e.g. Sep-2016 would become 201609/, Int64.Type),
#âAdded MonthYearâ = Table.AddColumn(#âAdded MonthYearNumâ, âMonthYearâ, each [Month] & â-â & Text.End(Text.From([Year]),2)),
#âAdded MonthYearLongâ = Table.AddColumn(#âAdded MonthYearâ, âMonthYearLongâ, each [Month] & â-â & Text.From([Year])),
#âAdded QtrYearâ = Table.AddColumn(#âAdded MonthYearLongâ, âQtrYearâ, each [Quarter] & " " & Text.From([Year])),
#âAdded QtrYrNumâ = Table.AddColumn(#âAdded QtrYearâ, âQtrYrNumâ, each [Year]*100+[QtrNum], Int64.Type),
#âAdded WeekdayNumâ = Table.AddColumn(#âAdded QtrYrNumâ, âWeekdayNumâ, each Date.DayOfWeek([Date]), Int64.Type),
#âAdded Weekday Nameâ = Table.AddColumn(#âAdded WeekdayNumâ, âWeekdayâ, each Text.Start(Date.DayOfWeekName([Date]),3), type text),
#âAdded WeekdayWeekendâ = Table.AddColumn(#âAdded Weekday Nameâ, âWeekdayWeekendâ, each if [WeekdayNum] = 0 or [WeekdayNum] = 6
then âWeekendâ
else âWeekdayâ),
#âDuplicated Columnâ = Table.DuplicateColumn(#âAdded WeekdayWeekendâ, âYearâ, âYear Textâ),
#âChanged Typeâ = Table.TransformColumnTypes(#âDuplicated Columnâ,{{âYear Textâ, type text}}),
#âUppercased Textâ = Table.TransformColumns(#âChanged Typeâ,{{âMonthâ, Text.Upper, type text}})
in
#âUppercased Textâ
Disclaimer, I did not design this complete table - I âstoleâ most of it from Avi Singhâs âUltimate Calendar Tableâ that he publishes frequently with his YouTube Webinars
Here is another set of M code that gives you a bit more information than the one provided. There are many different ways to set this up. Attached, is a copy of the code that I use. @Melissa played a major part in helping develop this. Also, when asking questions in the forum, please do a search for that topic before posting. There are numerous threads in the forum regarding the setup of a proper Date Table.
Power BI Date Table Code with Offsets - 4-6-2020.txt (6.8 KB)
Thanks
Jarrett