Forum Discussion

m_holly10's avatar
m_holly10
Regular Visitor
4 years ago

Custom Fiscal Calendar Time Intelligence Measures

Hello Power BI Community,

 

We are in the process of trying to create the following time-intelligence measures using Fiscal Year, Fiscal Month & Fiscal Week fields.

 - Prior Month Weekly Average: Calculate [SelectedMeasure()]] for the prior fiscal month/number of weeks in the prior fiscal month

 - 3 Month Weekly Average: Calculate [SelectedMeasure()] for the prior 3 fiscal months/number of weeks in the prior 3 fiscal months

 -  Prior Year Weekly Average: Calculate [SelectedMeasure()] for the prior fiscal year/number of weeks in the prior fiscal year

 

This is the current code that we are using to try to calculate the 3 Month Fiscal Average, but we need to swap out the filters that are referencing the date key for filters that reference the fiscal date parts.

 

Test 3 Month Weekly Avg =

VAR MaxDateOnPreviousMonth = EOMonth(MAX('date'[date key]), -1)

VAR Result =

CALCULATE([Invoice Revenue Total],

DATESINPERIOD('Date'[Date Key], MaxDateOnPreviousMonth,-3, MONTH)

)

Return result/13

 

The below screenshot shows the period ranges that need to be included for each caclculation. The 'Invoice Revenue Total' is a calculated measure in our data model and not a calculated column. The fact tables in our model are at a daily level of granularity.

 

 

We are not able to use the out-of-the-box time intelligence calculations because we dont have an actual 'Fiscal Date' field and field with a 'Date' datatype is required for using those measures. We are stuggling to find the correct DAX code to achieve these averages. Please help! Here is a sample data table for testing.

 

End of WeekFiscal YearFiscal Month Fiscal WeekFiscal Week NameInvoice Revenue Total
1/9/20212021Jan-211FY21 WK1$1,000.00
1/16/20212021Jan-212FY21 WK2$1,232.00
1/23/20212021Jan-213FY21 WK3$1,232.00
1/30/20212021Jan-214FY21 WK4$1,234.00
2/6/20212021Feb-215FY21 WK5$4,321.00
2/13/20212021Feb-216FY21 WK6$2,243.00
2/20/20212021Feb-217FY21 WK7$3,324.00
2/27/20212021Feb-218FY21 WK8$3,324.00
3/6/20212021Mar-219FY21 WK9$4,433.00
3/13/20212021Mar-2110FY21 WK10$4,582.64
3/20/20212021Mar-2111FY21 WK11$5,002.66
3/27/20212021Mar-2112FY21 WK12$5,422.67
4/3/20212021Mar-2113FY21 WK13$5,842.69
4/10/20212021Apr-2114FY21 WK14$6,262.71
4/17/20212021Apr-2115FY21 WK15$6,682.72
4/24/20212021Apr-2116FY21 WK16$7,102.74
5/1/20212021Apr-2117FY21 WK17$7,522.76
5/8/20212021May-2118FY21 WK18$7,942.77
5/15/20212021May-2119FY21 WK19$8,362.79
5/22/20212021May-2120FY21 WK20$8,782.81
5/29/20212021May-2121FY21 WK21$9,202.82
6/5/20212021Jun-2122FY21 WK22$9,622.84
6/12/20212021Jun-2123FY21 WK23$10,042.86
6/19/20212021Jun-2124FY21 WK24$10,462.87
6/26/20212021Jun-2125FY21 WK25$10,882.89
7/3/20212021Jun-2126FY21 WK26$11,302.91
7/10/20212021Jul-2127FY21 WK27$11,722.92
7/17/20212021Jul-2128FY21 WK28$12,142.94
7/24/20212021Jul-2129FY21 WK29$12,562.96
7/31/20212021Jul-2130FY21 WK30$12,982.97
8/7/20212021Aug-2131FY21 WK31$13,402.99
8/14/20212021Aug-2132FY21 WK32$13,823.01
8/21/20212021Aug-2133FY21 WK33$14,243.02
8/28/20212021Aug-2134FY21 WK34$14,663.04
9/4/20212021Sep-2135FY21 WK35$15,083.06
9/11/20212021Sep-2136FY21 WK36$15,503.07
9/18/20212021Sep-2137FY21 WK37$15,923.09
9/25/20212021Sep-2138FY21 WK38$16,343.11
10/2/20212021Sep-2139FY21 WK39$16,763.12
10/9/20212021Oct-2140FY21 WK40$17,183.14
10/16/20212021Oct-2141FY21 WK41$17,603.16
10/23/20212021Oct-2142FY21 WK42$18,023.17
10/30/20212021Oct-2143FY21 WK43$18,443.19
11/6/20212021Nov-2144FY21 WK44$18,863.21
11/13/20212021Nov-2145FY21 WK45$19,283.22
11/20/20212021Nov-2146FY21 WK46$19,703.24
11/27/20212021Nov-2147FY21 WK47$20,123.26
12/4/20212021Dec-2148FY21 WK48$20,543.27
12/11/20212021Dec-2149FY21 WK49$20,963.29
12/18/20212021Dec-2150FY21 WK50$21,383.31
12/25/20212021Dec-2151FY21 WK51$21,803.32
1/1/20222021Dec-2152FY21 WK52$22,223.34
1/8/20222022Jan-221FY22 WK1$22,643.36
1/15/20222022Jan-222FY22 WK2$23,063.37
1/22/20222022Jan-223FY22 WK3$23,483.39
1/29/20222022Jan-224FY22 WK4$23,903.41
2/5/20222022Feb-225FY22 WK5$24,323.42
2/12/20222022Feb-226FY22 WK6$24,743.44
12/31/20222022Dec-2252FY22 WK52$25,163.46

 

Thank you.

1 Reply

  • "Prior Month Weekly Average"

     

    That screaming sound you hear is every developer who ever tried to explain to management that weeks and months are incompatible.

     

    You must have a calendar table.  It must be contiguous.  It is highly recommended that you maintain it outside of Power BI.  If you attempt to implement your fiscal year "logic" in Power BI you will fail. Miserably. 

     

    Once you have a calendar table in place with the requisite flags (week number, quarter number, fiscal year number for each date)  you can then write your above measures.  Be always very clear that the measures you are asked to write will be at best misleading and at worst useless.