Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jpt1228
Responsive Resident
Responsive Resident

Working with 4 week time periods in calculations

Hello first off I want to thank all the smart people on here for helping. I am having a difficult time importing data and wokring with it. The main problem is the data that I am working with is available every 4 weeks or 13 periods a year. I want to be able to compare 4 weeks VS the same time last year, 12 weeks VS same time last year, 24 and 52 weeks. I can do this with data that is reported by day or calendar month but when a single month has data reported 2x in that single month (see red text for October 2016) I can't figure it out. Thinking I have to index the dates and compare index 2 2016 VS index 2 2017 rather than Month and date.

 

 GeographyData    
 Region 1  Region 2  
Time DescriptionSum of DollarsSum of UnitsSum of StoresSum of DollarsSum of UnitsSum of Stores
Quad End 2015-Dec-275430.37919.8633.05356315.01310225.17642.59
Quad End 2015-Nov-015808.8451017.75131.35156575.39510181.96241.194
Quad End 2015-Nov-296184.4621055.39833.51659102.90410063.87641.914
Quad End 2015-Oct-045869.1371025.7230.76754549.4769333.30840.558
Quad End 2015-Sep-065887.9351020.28129.75952937.1189419.19541.054
Quad End 2016-Apr-176058.8321035.38633.0364915.98511138.63446.263
Quad End 2016-Aug-076236.936107635.05465259.91312067.02550.706
Quad End 2016-Dec-256888.4861190.80436.88871932.46612679.65951.345
Quad End 2016-Feb-216148.1421042.62833.03862084.64111326.15443.644
Quad End 2016-Jan-246238.8781046.72831.85261564.93810429.74743.07
Quad End 2016-Jul-106099.7031132.96735.14465744.35712036.18850.281
Quad End 2016-Jun-126111.7061052.3334.66763802.05511608.62450.297
Quad End 2016-Mar-206003.0691014.52133.36763433.70411143.24945.597
Quad End 2016-May-156007.6971013.28834.54564151.67411706.14349.661
Quad End 2016-Nov-276821.7381210.22835.99472619.22812812.8251.581
Quad End 2016-Oct-026455.8881100.78535.74668048.31411866.14451.532
Quad End 2016-Oct-306511.4041182.85635.61870969.90914193.52751.509
Quad End 2016-Sep-046495.2761100.69137.11266800.45911571.23851.057
Quad End 2017-Apr-167425.211362.24238.02381833.9215124.92752.31
Quad End 2017-Feb-196859.9721192.37636.63177287.62413834.49251.934
Quad End 2017-Jan-226613.7041149.87137.09872449.46512385.60651.428
Quad End 2017-Mar-197585.0671341.8736.81781206.09614608.74851.917
1 ACCEPTED SOLUTION

Hi @jpt1228,

 

I was looking at your data and since you have a value every 4 weeks, I believe that the fastest way to have this is to calculate the number of the week and then divide that by 4 this will give you the 1 to 13 needed index for each row. I tried to made just with week number but due to the 29 February the number was off by one week in 2017.

 

Create a custom column with this formula and then use this to make the comparision between periods.

 

ID_ROW =
DIVIDE (
    WEEKNUM ( FORMAT ( RIGHT ( Geography[Time Description], 11 ), "dd-mm-yyyy" ) ),
    4
)

I'm assuming that your download always is with the format "Quad End 2017-Apr-16" that is why I make the extration for date values with the RIGHT formula and convert it to date.

 

As you can see below all the values are as you need and repeated dates in the same month assume different values.

 

ID_Rows.png

 

Hope this helps,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
MFelix
Super User
Super User

Hi @jpt1228,

 

I don't know if this can help but if the lines are incremental so value of end of month is the sum of both lines tou can use the TOTALMTD / TOTALQTD / TOTALYTD and you can compare the periods in differents year. If the line are not summed maybe you can do it with a validation of the maximum date and then converting that line to the end of month and use the previous formulas.

 

To help you better can you please tell me if the two line you identify are to be sum together or consider separatly, if so wich one does count for end result the October-02 or October-30?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



jpt1228
Responsive Resident
Responsive Resident

Hi @MFelix The data is for the 4 weeks ending on that date. So 4 Weeks (Reported as Quad) on Apr 16 would be data from March 20th-April 16th. In the October data example Quad End 2016-Oct-30 would include data from October 3rd 2016-October 30th. Quad End 2016-Oct-02 would include data from September 5th 2016-October 2nd 2016. If Quad end 2016-Oct-30 would be the 11th period out of 13 I want to be able to compare the 11th period of 2017 VS the 11th period 2016. I can't use the date because depending on the calendar there may be 2 reporting times in the same month.

 

Does this help?

 

image.png

 

Time DescriptionGeographyDollarsUnits Stores 
Quad End 2017-Apr-16TOTAL US - NATURAL CHANNEL81833.9215124.927              52.31
Quad End 2017-Apr-16MID-ATLANTIC - STANDARD REGION - NAT CHNL7425.211362.242              38.02
Quad End 2017-Mar-19TOTAL US - NATURAL CHANNEL81206.09614608.748              51.92
Quad End 2017-Mar-19MID-ATLANTIC - STANDARD REGION - NAT CHNL7585.0671341.87              36.82
Quad End 2017-Feb-19TOTAL US - NATURAL CHANNEL77287.62413834.492              51.93
Quad End 2017-Feb-19MID-ATLANTIC - STANDARD REGION - NAT CHNL6859.9721192.376              36.63
Quad End 2017-Jan-22TOTAL US - NATURAL CHANNEL72449.46512385.606              51.43
Quad End 2017-Jan-22MID-ATLANTIC - STANDARD REGION - NAT CHNL6613.7041149.871              37.10
Quad End 2016-Dec-25TOTAL US - NATURAL CHANNEL71932.46612679.659              51.35
Quad End 2016-Dec-25MID-ATLANTIC - STANDARD REGION - NAT CHNL6888.4861190.804              36.89
Quad End 2016-Nov-27TOTAL US - NATURAL CHANNEL72619.22812812.82              51.58
Quad End 2016-Nov-27MID-ATLANTIC - STANDARD REGION - NAT CHNL6821.7381210.228              35.99
Quad End 2016-Oct-30TOTAL US - NATURAL CHANNEL70969.90914193.527              51.51
Quad End 2016-Oct-30MID-ATLANTIC - STANDARD REGION - NAT CHNL6511.4041182.856              35.62
Quad End 2016-Oct-02TOTAL US - NATURAL CHANNEL68048.31411866.144              51.53
Quad End 2016-Oct-02MID-ATLANTIC - STANDARD REGION - NAT CHNL6455.8881100.785              35.75

Hi @jpt1228,

Taking your information I agree that the best way would be to indexed the data to the period-year and then.compare the two in different years.

Regards,
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



jpt1228
Responsive Resident
Responsive Resident

I am a new user of PowerBI - Do you have any recommended DAX formulas, or how would I go about assigning an index period to the specific time frame?

Hi @jpt1228,

 

I was looking at your data and since you have a value every 4 weeks, I believe that the fastest way to have this is to calculate the number of the week and then divide that by 4 this will give you the 1 to 13 needed index for each row. I tried to made just with week number but due to the 29 February the number was off by one week in 2017.

 

Create a custom column with this formula and then use this to make the comparision between periods.

 

ID_ROW =
DIVIDE (
    WEEKNUM ( FORMAT ( RIGHT ( Geography[Time Description], 11 ), "dd-mm-yyyy" ) ),
    4
)

I'm assuming that your download always is with the format "Quad End 2017-Apr-16" that is why I make the extration for date values with the RIGHT formula and convert it to date.

 

As you can see below all the values are as you need and repeated dates in the same month assume different values.

 

ID_Rows.png

 

Hope this helps,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



jpt1228
Responsive Resident
Responsive Resident

Hi @MFelix - Since I am new to Power BI and DAX I used the query editor to extract the date, created a year column, and week in year and divided that column by 4. Then renamed that "Quad Week Period" which is the long version of your formula.

 

let
Source = Excel.Workbook(File.Contents("C:\Users\Jon\Desktop\TDP Test File.xlsx"), null, true),
#"Expanded Data" = Table.ExpandTableColumn(Source, "Data", {"Column1", "Column2", "Column3"}, {"Data.Column1", "Data.Column2", "Data.Column3"}),
#"Promoted Headers" = Table.PromoteHeaders(#"Expanded Data", [PromoteAllScalars=true]),
#"Removed Other Columns" = Table.SelectColumns(#"Promoted Headers",{"Time Description", "Geography", "TDP"}),
#"Inserted Last Characters" = Table.AddColumn(#"Removed Other Columns", "Last Characters", each Text.End(Text.From([Time Description], "en-US"), 11), type text),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Last Characters",{{"Last Characters", type date}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Last Characters", "Date"}}),
#"Inserted Week of Year" = Table.AddColumn(#"Renamed Columns", "WeekOfYear", each Date.WeekOfYear([Date]), type number),
#"Inserted Division" = Table.AddColumn(#"Inserted Week of Year", "Inserted Division", each [WeekOfYear] / 4, type number),
#"Changed Type1" = Table.TransformColumnTypes(#"Inserted Division",{{"Inserted Division", Int64.Type}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type1", "Year", each Date.Year([Date]), type number),
#"Renamed Columns1" = Table.RenameColumns(#"Inserted Year",{{"Inserted Division", "Quad Week Period"}})
in
#"Renamed Columns1"

 

One last question - How do I create a custom calculation to calculate the numerical difference from Quad Week Period 4 in 2017 VS the same Quad Week Period 4 in 2016? I have used the formula to sum the month and then pull in the same time last year like below.

 

If period 4 in 2016 was 10 and period 4 in 2017 was 12 I want the result to be 2 which is the difference from 12-10=2

 

TotalRevenueThisPeriodLY = CALCULATE(SalesDataAggregated[TotalRevenue], FILTER(ALL(Dates), Dates[CalendarYear] = MAX(Dates[CalendarYear])-1), SAMEPERIODLASTYEAR(Dates[Date]))

 

 

Hi @jpt1228,

 

I have made a table with Week, Period, and Year and added these columns:

 

 

ID = Table2[Year]&Table2[Period]

column = IF (
          Table2[Year] = MIN ( Table2[Year] ),
          BLANK (),
          Table2[Week]
          - LOOKUPVALUE ( Table2[Week], Table2[ID], Table2[Year] - 1 & Table2[Period] )
         )

The result was this:

 

Weeks.png

 

Regards,

MFelix

 

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.