sql-bi / daxdatetemplate Goto Github PK
View Code? Open in Web Editor NEWPower BI template to create a Date table in DAX
License: MIT License
Power BI template to create a Date table in DAX
License: MIT License
When a new PBIX file is created from the template DirectQuery connections cannot be added to the model because the Date table that is created is considered as being an imported dataset and in the model cannot be mixed DQ and Imported datasets.
The error message that is generated after adding a direct query connection is:
Failed to save modifications to the server. Error returned: 'Partitions that contain a full dataset (not sampled data) have to be configured for DirectQuery and Full DataViews, or use Import query mode to retrieve data. This model appears to have partitions that are non-compliant. Please check partition configuration.
'.
What would be the way to use the template with DQ?
When setting
FiscalCalendarFirstMonth = 1
and
CalendarRange = "Calendar"
the calendar only creates dates up until Dec. 28, 2019. Using any other month for FiscalCalendarFirstMonth the calendar will populate up to Dec. 31, 2019.
But the generated calendar starts at 12/31/2017 marked as F 2018 FQ4 and not F 2018 FQ1. I am sure I have some setting wrong here but cannot figure out which it is. Thanks,
I noticed an error showing on CustomFiscalRawDays...it doesn't show a problem now but was wondering if it would be resolved.
I did read the "Future Year" comment, but continue to have a question. I to would like to change the LastYear to be in the future, however I'm a novice as well and don't know which part of the parameter to change. Also would like to make sure that regardless of anything else, the LastYear indicated is through 12/31/xxxx or the last fiscal day. Don't really care which one, but if I indicate the last year is 2021, then I would like 12/31/2021 or 6/30/2022. Seems right now the last line for the current year is random and showing as 11/29/2019 before I change anything.
Var TodayReference = VAR CurrentDate = TODAY()
Return
Date(Year(CurrentDate)+2,Month(CurrentDate),DAY(CurrentDate))
VAR LastYear = YEAR ( TodayReference )
Should the year reference in "Fiscal Week Year" not be FiscalYear instead of CalYear ?
First of all: thank you for this. You are an authoritative reference for all things PowerBI and one of the first people I look for if I'm trying to fix/understand the "right way" to do something rather than trying other hack-y solutions to a thorny problem.
I read through the documentation and cannot find anything referencing the hierarchies you created. You have renamed the elements so I'm not 100% sure of the underlying references. Is it as simple as (for example) Calendar Quarters is composed of Calendar Year/Calendar Quarter/Calendar Month? Or might you have used "Calendar Month Year" or something else?
Thanks. I cannot use the template directly- I have other existing PBIX to add this to and it's a lot less work to recreate the sorting/naming/hiding than to start over with everything else- plus I'd like to understand.
Implement settings to enable the generation of a weekly calendar with the following requirements:
The fiscal year begins on the Saturday closest to 1 July and ends on Friday closest to 30 June. The accounting year is split into four accounting quarters, each consisting of 13 weeks. The accounting quarter is split into three accounting months using the “5-4-4” method (that is, the first month in a quarter consists of five weeks; the second and third months consists of four weeks each). Periodically, like last year, to ensure the end of the fiscal year closest to 30 June, the fiscal year will consist of 53 weeks for fiscal year reporting periods.
Hey guys,
Changing the FirstDayOfWeek setting from 0 pulls up the following error:
"CustomFiscalPeriods table does not match FirstDayOfWeek setting"
Marco Russo had provided a workaround to the problem that I've been trying hard to understand and reverse engineer, however I haven't had any luck. This functionality is crucial to my weekly time intelligence analysis.
Thank you
Hi, is it possible to add calculations for Swedish Midsummer Eve
In Excel its calculated as:
Midsummer Eve = DATE(B1;6;19+(7-WEEKDAY(DATE(B1;6;20))))
Midsummer Day= DATE(B1;6;19+(7-WEEKDAY(DATE(B1;6;19))))
Where B1 is the year
In the 1.06 release, the Date table appears empty using the default settings.
Hi Marco
What is the purpose of [Fiscal WeekYearOrder]? (and by extension: [Calendar WeekYearOrder])
The name implies that it is used as the "Sort By Column" for [Fiscal Week Year]. However, [Fiscal YearWeekNumber] serves this purpose in addition to various Time Intelligence methods.
Thanks,
Simon
Is there any way of using the Date table from the template in an existing Power BI report? Copying the table loses the formatting of the table including the sort orders for the various columns. Unfortunately I'm not in a position to start the entire report from scratch in the Date template.
Hi, I've tried to amend the initial parameters to enables the time period to end 31 March 2020 (as the end of this current fiscal year) but I just can't get it to work - I'm probably doing it wrongly as I'm an utter novice.
So, can someone be really kind and let me have the exact text to paste into the query to achieve this. My table currently ends in December 2019, so three month's short for my needs!
Thanks! and fingers crossed...
On line 975 the calculation for 'Fiscal Month Year' refers to to the variable calendar year instead of fiscal year.
VAR FirstDayOfWeek is set to 1, for Monday as the first day of the week. Yet, the measure 'Fiscal DatePreviousWeek' has the last day as Monday of the current week. Why would it not display Sunday? I'm not following the logic.
Good morning (or Good day!),
From the previous issue, you found that I have been standardizing my date tables across all reports in Power BI. Yesterday, I got everything updated and appearing to function as desired.
Today, the start of the new fiscal year, all of my prior week measures went to "0". Inspecting a variable inside of one of the measures, PreviousFiscalYearWeek, should have provided the resulting value of 6243, today's "Fiscal YearWeekNumber" - 1. Instead, the result was -1.
This was odd, zero minus one equals -1. Why would this sequential value become zero? So I looked at the Date table. No new entry has been created for today! Here are the first few lines of the table definition:
VAR TodayReference = TODAY () -- Change this if you need to use another date as a reference "current" day
VAR FirstYear = 2012
VAR LastYear = YEAR ( TodayReference )
VAR FiscalCalendarFirstMonth = 9 -- For Fiscal 52-53 weeks (start depends on rules) and Gregorian (starts on the first of the month)
VAR FirstDayOfWeek = 1 -- Use: 0 - Sunday, 1 - Monday, 2 - Tuesday, ... 5 - Friday, 6 - Saturday
VAR TypeStartFiscalYear = 1 -- Fiscal year as Calendar Year of : 0 - First day of fiscal year, 1 - Last day of fiscal year
VAR IsoCountryHolidays = "US" -- Use only supported ISO countries or "" for no holidays
VAR WeeklyType = "Last" -- Use: "Nearest" or "Last"
VAR QuarterWeekType = "445" -- Supports only "445", "454", and "544"
VAR CalendarRange = "FiscalGregorian" -- Supports "Calendar", "FiscalGregorian", "FiscalWeekly"
Should this not generate the row for today at midnight each day?
Hey Marco,
VAR TodayReference =
TODAY () -- Change this if you need to use another date as a reference "current" day
VAR FirstYear = 2008
VAR LastYear =
YEAR ( TodayReference )
VAR FiscalCalendarFirstMonth = 9 -- For Fiscal 52-53 weeks (start depends on rules) and Gregorian (starts on the first of the month)
VAR FirstDayOfWeek = 0 -- Use: 0 - Sunday, 1 - Monday, 2 - Tuesday, ... 5 - Friday, 6 - Saturday
VAR WeeklyType = "Last" -- Use: "Nearest" or "Last"
VAR QuarterWeekType = "445" -- Supports only "445", "454", and "544"`
For some reason I'm getting FQ5 and FQ6 on the Fiscal Quarter and Fiscal QuarterNumber. Is that correct? Also, what columns are the columns for the Fiscal 52-53? I see some that start with FW (perhaps Fiscal Weekbased?) and others that start with Fiscal
I use the Template all over my models but I would greatly appreciate a Detailed Week Number in format 'W17 - 20/04/20-26/04/20' to use in slicers.
I have added a column for that already, but would be great to have this embedded.
Hi,
I was wondering if the code for generating the Dax Date table could be shared by its self so it can be easily used outside of Powerbi such as in Tabular models.
Cheers
Hi,
So last year was a leap year, and now I'm having some issues with the generated Date-table from SQLBI.
The calendar should look like this, for 2021:
This is how it looks, however, when using your Date-table:
So W53 should include the first three days of 2021, but it doesn't, causing every week after to shift to the next week.
I recently found this project, and it works wonders.
Now, I am having trouble with 2021 where 1/1-2021 is marked as Calendar Week 1 instead of Calendar Week 53 of 2020, and 4/1-2021 is marked as Calendar Week 2 and so on.
I can't seem to find the right combination of settings to get the week numbers that I would like. Am I misunderstanding how the field Calendar Week should/could be flexible?
Current Output:
Date | Calendar Week |
---|---|
28-12-2020 | W53 |
29-12-2020 | W53 |
30-12-2020 | W53 |
31-12-2020 | W53 |
01-01-2021 | W01 |
02-01-2021 | W01 |
03-01-2021 | W01 |
04-01-2021 | W02 |
05-01-2021 | W02 |
Wanted output:
Date | Calendar Week |
---|---|
28-12-2020 | W53 |
29-12-2020 | W53 |
30-12-2020 | W53 |
31-12-2020 | W53 |
01-01-2021 | W53 |
02-01-2021 | W53 |
03-01-2021 | W53 |
04-01-2021 | W01 |
05-01-2021 | W01 |
Current settings in PBIX file:
VAR FirstYear = 2019
VAR LastYear =
YEAR ( TodayReference )
VAR FiscalCalendarFirstMonth = 1 -- For Fiscal 52-53 weeks (start depends on rules) and Gregorian (starts on the first of the month)
VAR FirstDayOfWeek = 1 -- Use: 0 - Sunday, 1 - Monday, 2 - Tuesday, ... 5 - Friday, 6 - Saturday
VAR TypeStartFiscalYear = 1 -- Fiscal year as Calendar Year of : 0 - First day of fiscal year, 1 - Last day of fiscal year
VAR IsoCountryHolidays = "US" -- Use only supported ISO countries or "" for no holidays
VAR WeeklyType = "Nearest" -- Use: "Nearest" or "Last"
VAR QuarterWeekType = "445" -- Supports only "445", "454", and "544"
VAR CalendarRange = "FiscalGregorian" -- Supports "Calendar", "FiscalGregorian", "FiscalWeekly"
I think the template would benefit from a more elaborate Period measure -- something like this:
Period =
-- Parameters
VAR IsDMY = TRUE()
VAR DayFormat = "d"
VAR MonthFormat = "MMMM"
VAR YearFormat = "yyyy"
VAR LabelText = UNICHAR ( 128197 ) & " "
-- Formats
VAR DayMonthFormat = IF ( IsDMY, DayFormat & " " & MonthFormat, MonthFormat & " " & DayFormat )
VAR FullYearFormat = IF ( IsDMY, " ", ", " ) & YearFormat
VAR FullDateFormat = DayMonthFormat & FullYearFormat
-- Input dates
VAR MinDate = MIN ( 'Date'[Date] )
VAR MaxDate = MAX ( 'Date'[Date] )
-- Formatted dates
VAR StartDate = FORMAT ( MinDate, FullDateFormat )
VAR EndDate = FORMAT ( MaxDate, FullDateFormat )
VAR StartDay = FORMAT ( MinDate, DayFormat )
VAR EndDay = FORMAT ( MaxDate, DayFormat )
VAR StartMonth = FORMAT ( MinDate, MonthFormat )
VAR EndMonth = FORMAT ( MaxDate, MonthFormat )
VAR StartYear = FORMAT ( MinDate, FullYearFormat )
VAR EndYear = FORMAT ( MaxDate, FullYearFormat )
VAR StartDayMonth = FORMAT ( MinDate, DayMonthFormat )
VAR EndDayMonth = FORMAT ( MaxDate, DayMonthFormat )
-- Result
RETURN
LabelText &
SWITCH (
TRUE(),
-- Only one day is selected
StartDate = EndDate,
EndDate,
-- Dates fall within the same month
AND ( StartMonth = EndMonth, StartYear = EndYear ),
IF (
IsDMY,
StartDay & "–" & EndDayMonth,
StartDayMonth & "–" & EndDay
)
& EndYear,
-- Dates fall within the same year
StartYear = EndYear,
StartDayMonth & " – " & EndDate,
-- Dates in different years
StartDate & " – " & EndDate
)
More details, including the description of parameters and the measure in action, can be found here:
http://community.powerbi.com/t5/Quick-Measures-Gallery/Date-range/m-p/365203
I've downloaded the 1.0.2 version, opened the PBIX file, and changed "VAR FiscalCalendarFirstMonth = 9" to "VAR FiscalCalendarFirstMonth = 1" instead.
After that change, the "Fiscal Year" is showing "F 2009" for a "Date" value of "1/1/2008 12:00:00 AM"
Shouldn't the "Fiscal Year" be "F 2008"?
The usage notes ask that ISO codes are used for countries - however, "UK" is used in the code whereas the relevant ISO code is "GB".
Marco,
When I implement DAX Date Template v.1.14 Calendar into my project, I found if I set up the one year (2020) calendar, the last Week 12/27/2020 - 1/2/2021 for the FW EndOfWeek is 1/2/2021, but that value is empty (or null); see the screenshot
If I want to get the year 2020 end week Week 12/27/2020 - 1/2/2021 for the FW EndOfWeek value, I need to set up two years (2020 & 2021) calendar. Is this the only way to get the ending week value if this cross to next year?
Thank you very much!
Reproducible using V1.12 template with no changes.
Var TodayReference = VAR CurrentDate = TODAY()
Return
Date(Year(CurrentDate)+2,Month(CurrentDate),DAY(CurrentDate))
VAR LastYear = YEAR ( TodayReference )
I have replace for future years as people will use for predictive. There may be a better way to code it but I am just slightly better than novice. May be something to think about changing.
Hi,
based on the column "Day type" and on an internet feed
https://community.powerbi.com/t5/Desktop/Calculate-the-current-business-day-number-in-the-month/m-p/561508#M264882
I've created the column Working Day Number
Would it be integrated directly in the table and programmed perfectly, it would be perfect !
thx in advance
Any reason the data type for date fields is left as date/time versus date?
If you choose IsoCountryHolidays = "AU" then the date table fails to load.
You get an error that the primary date key must contain unique values.
Troubleshooting I see that Anzac Day and Easter Sunday fall on the same day in 2011. You would need to calculate the Easter holidays days first, and continue to offset the 'normal' holiday by +1 until you reach a non-Easter holiday working day.
I'm trying to figure out the required change, possibly to SubstituteHolidayOffset.
It'd be interesting to look at the week of the quarter typically from 1 to 13 instead of the 53 annual weeks. What do yo uthink?
Is it already in there?
What is the best way to handle when fixed date holidays like New Years, Independence Day, Christmas fall on a weekend and have an Observed holiday? For Example, Independence day 2020 falls on a Saturday and will be Observed on Friday 7/3/2020.
Hi,
I get the red lines under this part of the code.
VAR CustomFiscalRawDays =
GENERATE ( FiscalPeriods; CALENDAR( [FW StartOfYear]; [FW EndOfYear] ) )
It is in both the pbix and the pbit.
Hello!
I've been trying to set up a fiscal calendar year and so far the code has not given me any trouble.
VAR WeeklyCalendarType = "Weekly" -- Supports "Weekly", "Custom"
-- Set the working days - 0 = Sunday, 1 = Monday, ... 6 = Saturday
VAR WorkingDays =
DATATABLE ( "WorkingDayNumber"; INTEGER; { { 1 }; { 2 }; { 3 }; { 4 }; { 5 } } ) --
-- Use CustomFiscalPeriods in case you need arbitrary definition of weekly fiscal years
-- Set "UseCustomFiscalPeriods" to TRUE in order to use CustomFiscalPeriods
VAR UseCustomFiscalPeriods = FALSE
-- Set "IgnoreWeeklyFiscalPeriods" to TRUE in order to ignore the WeeklyFiscalPeriods
-- You should set IgnoreWeeklyFiscalPeriods to TRUE only when UseCustomFiscalPeriods is TRUE, too
VAR IgnoreWeeklyFiscalPeriods = FALSE
-- Include here your own definition of custom fiscal periods
VAR CustomFiscalPeriods =
FILTER (
DATATABLE (
"Fiscal YearNumber"; INTEGER;
"FirstDayOfYear"; DATETIME;
"LastDayOfYear"; DATETIME;
{
-- IMPORTANT!!! The first day of each year must be a weekday corresponding to the definition of FirstDayOfWeek
-- If you want to use this table, remember to set the UseCustomFiscalPeriods variable to TRUE
-- If the IgnoreWeeklyFiscalPeriods is TRUE, there are no warnings in case the FirstDayOfWeek
-- does not match the first day of the year
{ 2016; "2015-06-28"; "2016-07-02" };
{ 2017; "2016-07-03"; "2017-07-01" };
{ 2018; "2017-07-02"; "2018-06-30" };
{ 2019; "2018-07-01"; "2019-06-29" }
}
);
UseCustomFiscalPeriods
)`
Once I've set up the calendar and I try to filter by Fiscal Month Year (Jan 2020) and I check the dates, it shows me the calendar dates (from the 1st up to the 31 of Jan 2020).
I would really appreciate if you could help me out.
Thank you!
Hi there,
Just downloaded v1.14 and found a syntax error in line 704.
I downloaded the latest "DAX Date Template.pbit" and "DAX Date Template.pbix" files, but both of them aren't opening up in my Power BI Desktop app. The error is : Unable to open template - DAX Date Template.pbit is corrupt or an invalid report file.
I am on the following version of the Power BI Desktop application, which was updated 2 days ago on 8/14/2020.
Release:
August 2020
Product Version:
2.84.701.0 (20.08) (x64)
OS Version:
Microsoft Windows NT 10.0.19041.0 (x64 en-US)
CLR Version:
4.7 or later [Release Number = 528372]
Feedback Type:
Frown (Error)
When clicking on the Date table in the fields list in Power BI Desktop, users see the large DAX expression and it consumes all of the screen.
Is there a way to hide the DAX expression from end users?
The Calendar Week Year and Calendar RelativeWeekPos were wrong calculated for 2021.
It should be: 1-3 January are week 53 and Week 1 of 2021 start at January 4th
Now Week 1 is January 1st-3th and Week 2 starts at January 4th.
How can ths be fixed?
instead of date table with m in powerquery he miss parameter (from date To date)
It looks like the Calendar RelativeWeekPos (and Month, Quarter, Year) are backwards. The documentation says negative values should be in the past and positive values are in the future relative to the TodayReference. At line# 822, if you flip the calculation from
VAR RelativeWeekPos = CurrentWeekPos - YearWeekNumber
to VAR RelativeWeekPos = YearWeekNumber - CurrentWeekPos
it will work.
I am new to DAX and PowerBI and already like it. I am trying to use the template but an error keeps poping up regarding fiscal Periods. A line in the code has two parameters FW StarOfYear and FW EndOfYear, I have tried to manually filling with custom dates '2019-04-01' and '2020-3-31' but I get an error: "Column in Table '' contains a duplicate value '4/1/2019' and this is not allowed for columns on the one side of a many-to-one relationship or for columns that are used as the primary key of a table."
Any ideas what is wrong ?
Wondering if you could add Week Start Date. Or, maybe I missed that field. Reason: If I'm displaying a report for week 18-28 (2018 week 28) the execs might not be able to make the conversion very quickly to 08-Jul-2018.
how to change the first month of fiscal year to April-4,n not July -7, and how to change the holidays to Ontario, Canada holidays?
thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.