Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I need to create a "Cycle" column in my Date table to handle sales cycles.. A year comprises of 8 cycles (of around 45 days) with start and end dates as follows:
Cycle ------ Start Date ------ End Date
Cycle 1 2018 ------ 01/01/18 ------ 15/02/18
Cycle 2 2018 ------ 16/02/18 ------ 31/03/18
Cycle 3 2018 ------ 01/04/18 ------ 15/05/18
Cycle 4 2018 ------ 16/05/18 ------ 30/06/18
Cycle 5 2018 ------ 01/07/18 ------ 15/08/18
Cycle 6 2018 ------ 16/08/18 ------ 30/09/18
Cycle 7 2018 ------ 01/10/18 ------ 15/11/18
Cycle 8 2018 ------ 16/11/18 ------ 31/12/18
Start Date is always 1st or 16th of a month. End Date is always 15th or last day of a month.
Please help.
Solved! Go to Solution.
Please find the solution at : https://www.dropbox.com/s/x7ex9vd576hqfpj/period45Days.pbix?dl=0
Month Start = if(MOD(MONTH('Table'[Date]),3)=1 ,STARTOFMONTH('Table'[Date]),if((MOD(MONTH('Table'[Date]),3)=2 && (day('Table'[Date])<=15)),STARTOFMONTH(DATEADD('Table'[Date],-1,MONTH)),if(MOD(MONTH('Table'[Date]),3)=2 && DAY('Table'[Date])>=16,date(year('Table'[Date]),MONTH('Table'[Date]),16),date(year('Table'[Date]),(MONTH('Table'[Date])-1),16))))
Month END = if(MOD(MONTH('Table'[Date]),3)=0,ENDOFMONTH('Table'[Date]),if(MOD(MONTH('Table'[Date]),3)=2 && day('Table'[Date])>15,ENDOFMONTH(DATEADD('Table'[Date],1,MONTH)),if(MOD(MONTH('Table'[Date]),3)=2 && day('Table'[Date])<=15,date(year('Table'[Date]),MONTH('Table'[Date]),15),date(year('Table'[Date]),(MONTH('Table'[Date])+1),15))))
Cycle = SWITCH (
TRUE (),
format('Table'[Date],"MMDD")*1 <=215, "Cycle 1",
format('Table'[Date],"MMDD")*1 <=331, "Cycle 2",
format('Table'[Date],"MMDD")*1 <=515, "Cycle 3",
format('Table'[Date],"MMDD")*1 <=630, "Cycle 4",
format('Table'[Date],"MMDD")*1 <=815, "Cycle 5",
format('Table'[Date],"MMDD")*1 <=930, "Cycle 6",
format('Table'[Date],"MMDD")*1 <1115, "Cycle 7",
"Cycle 8"
)
in the case the above is fine. Also added
Year Cycle = 'Table'[Year] & " " & 'Table'[Cycle]
period No = CALCULATE(DISTINCTCOUNT('Table'[Year Cycle]),filter('Table','Table'[Date]<=EARLIER('Table'[Date])))
This will help in Power-BI-Working-with-Non-Standard-Time-Periods
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin
Hi @msingh2019 ,
FIrst, create a segmented table and import:
Second, create a column in date table:
Column =
CALCULATE(
MIN(Sheet3[Cycle]),
FILTER(
Sheet3,
'Table'[Date] >= Sheet3[Start Date] && 'Table'[Date] <= Sheet3[End Date]
)
)
(Do not create relationship between date table and segmented table.)
Best regards,
Lionel Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please find the solution at : https://www.dropbox.com/s/x7ex9vd576hqfpj/period45Days.pbix?dl=0
Month Start = if(MOD(MONTH('Table'[Date]),3)=1 ,STARTOFMONTH('Table'[Date]),if((MOD(MONTH('Table'[Date]),3)=2 && (day('Table'[Date])<=15)),STARTOFMONTH(DATEADD('Table'[Date],-1,MONTH)),if(MOD(MONTH('Table'[Date]),3)=2 && DAY('Table'[Date])>=16,date(year('Table'[Date]),MONTH('Table'[Date]),16),date(year('Table'[Date]),(MONTH('Table'[Date])-1),16))))
Month END = if(MOD(MONTH('Table'[Date]),3)=0,ENDOFMONTH('Table'[Date]),if(MOD(MONTH('Table'[Date]),3)=2 && day('Table'[Date])>15,ENDOFMONTH(DATEADD('Table'[Date],1,MONTH)),if(MOD(MONTH('Table'[Date]),3)=2 && day('Table'[Date])<=15,date(year('Table'[Date]),MONTH('Table'[Date]),15),date(year('Table'[Date]),(MONTH('Table'[Date])+1),15))))
Cycle = SWITCH (
TRUE (),
format('Table'[Date],"MMDD")*1 <=215, "Cycle 1",
format('Table'[Date],"MMDD")*1 <=331, "Cycle 2",
format('Table'[Date],"MMDD")*1 <=515, "Cycle 3",
format('Table'[Date],"MMDD")*1 <=630, "Cycle 4",
format('Table'[Date],"MMDD")*1 <=815, "Cycle 5",
format('Table'[Date],"MMDD")*1 <=930, "Cycle 6",
format('Table'[Date],"MMDD")*1 <1115, "Cycle 7",
"Cycle 8"
)
in the case the above is fine. Also added
Year Cycle = 'Table'[Year] & " " & 'Table'[Cycle]
period No = CALCULATE(DISTINCTCOUNT('Table'[Year Cycle]),filter('Table','Table'[Date]<=EARLIER('Table'[Date])))
This will help in Power-BI-Working-with-Non-Standard-Time-Periods
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin
Hi Amit,
I'm using the above DAX formula to create 12 Periods, but varies for the 1st period ~45days,12th Period~15day and rest of the periods from 16th - 15th ~30days
Hi @msingh2019
Currently, the only way I can think to do this in DAX is with a really crude SWITCH statement.
It's not elegant but it works.
Cycle =
SWITCH (
TRUE (),
MONTH ( 'Date'[Date] ) = 1, "Cycle 1 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 2 && DAY ( 'Date'[Date] ) <= 15, "Cycle 1 " & YEAR ( 'Date'[Date] ),
OR ( MONTH ( 'Date'[Date] ) = 2, MONTH ( 'Date'[Date] ) = 3 ), "Cycle 2 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 4, "Cycle 3 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 5 && DAY ( 'Date'[Date] ) <= 15, "Cycle 3 " & YEAR ( 'Date'[Date] ),
OR ( MONTH ( 'Date'[Date] ) = 5, MONTH ( 'Date'[Date] ) = 6 ), "Cycle 4 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 7, "Cycle 5 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 8 && DAY ( 'Date'[Date] ) <= 15, "Cycle 5 " & YEAR ( 'Date'[Date] ),
OR ( MONTH ( 'Date'[Date] ) = 8, MONTH ( 'Date'[Date] ) = 9 ), "Cycle 6 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 10, "Cycle 7 " & YEAR ( 'Date'[Date] ),
MONTH ( 'Date'[Date] ) = 11 && DAY ( 'Date'[Date] ) <= 15, "Cycle 7 " & YEAR ( 'Date'[Date] ),
OR ( MONTH ( 'Date'[Date] ) = 11, MONTH ( 'Date'[Date] ) = 12 ), "Cycle 8 " & YEAR ( 'Date'[Date] ),
""
)
Hope it helps.
Best regards,
Martyn
If I answered your question, please help others by accepting it as a solution.
A few thoughts...
1. Odd cycles always start at the first of the month.
2. Even cycles always start on the 16th of the month.
3. Last day of the month changes monthly. Solving for this can be done a few ways IMHO.
A) build a date table that builds out all 8 cycles by hand and includes a column for cycle number along with hard coded dates. Not elegant, but given you don't have a lot of dates/cycles to model, it might be the fastest.
B) Solve for 3 above, via a programmatic method: https://docs.microsoft.com/en-us/powerquery-m/date-endofmonth
Assuming you'll need to make decisions based on this table, you'll be testing against the start/end dates...
hope this helps.
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
136 | |
117 | |
101 | |
71 | |
61 |