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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
amaleranda
Post Patron
Post Patron

Date Table with a custom column 21 day cycle.

Hi PowerBI Gurus, 

 

I need to create a column in the date tabel as per below requirements.

 

 

"The base reporting cycle, for work metrics is 21 days. This is defined by calendar week number

e.g. (R1)2020 Week 1-3[4/Jan/2020 to 24/Jan/2020] ,

       (R2)2020Week 4-6[25/Jan/2020 to 14/Feb/2020],

       (R3)2020Week 7-9[15/Feb/2020 to 6/Mar/2020], etc

starting at on the first Saturday and progressing through until on third Friday.  this R# should be incrementtal as week goes on for instance 2020Week 10-12 should be R4 and so fourth. 

 

this R number should reset at the end of a week cycle of a new year too.

 

Trick is from 1/Jan/2020 to 3/Jan/2020 belongs part to a last 21 day cycle of the year 2019. 

 

If this does not explain well I can send you sample date tabel.

 

If anyone can help me with this, I really appriciate your help.

 

Regards

Amal Eranda

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

OK, @amaleranda this one is actually quite trivial, all you need is this column:

 

R = ROUNDUP([Sequentialish]/3,0)

Of course, getting the Sequentialish column took some WORK!!! I had to modify my Sequential quick measure here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231#M116 to account for you special circumstances. It's not really Sequential any longer but it works for this purpose.

 

Anyway, this is the column:

Sequentialish = 
VAR MaxWeeks = SUMMARIZE(ALL('Table'),'Table'[Year],"MaxWeek",MAX('Table'[WeekNum]))
VAR MyYear = [Year]
VAR MyStart = SUMX(FILTER(MaxWeeks,[Year]<MyYear),[MaxWeek])
VAR firstYear = CALCULATE(FIRSTNONBLANK('Table'[Year],1),ALL('Table'))
VAR __Table = 
    ADDCOLUMNS(
        GROUPBY(
            'Table',
            [Year],
            "__MaxWeek",MAXX(CURRENTGROUP(),[Weeknum])
        ),
        "__Count",COUNTROWS(FILTER(ALL('Table'),'Table'[Year]=EARLIER([Year]) && 'Table'[Weeknum]=[__MaxWeek]))
    )
    VAR __Count = COUNTROWS(FILTER(__Table,[Year]<MyYear && [__Count] < 7))
    VAR __Count2 = COUNTROWS(FILTER('Table',[Year]=MyYear && [Weeknum]=1))
VAR myNum = 
    IF(
        MyYear=firstYear,
        [WeekNum],
        IF([Weeknum]>1 && __Count2 <> 7,
            [Weeknum]-1,
            MyStart+[Weeknum]-__Count
        )
    )
RETURN myNum

I have attached a PBIX file for you.

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

OK, @amaleranda this one is actually quite trivial, all you need is this column:

 

R = ROUNDUP([Sequentialish]/3,0)

Of course, getting the Sequentialish column took some WORK!!! I had to modify my Sequential quick measure here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231#M116 to account for you special circumstances. It's not really Sequential any longer but it works for this purpose.

 

Anyway, this is the column:

Sequentialish = 
VAR MaxWeeks = SUMMARIZE(ALL('Table'),'Table'[Year],"MaxWeek",MAX('Table'[WeekNum]))
VAR MyYear = [Year]
VAR MyStart = SUMX(FILTER(MaxWeeks,[Year]<MyYear),[MaxWeek])
VAR firstYear = CALCULATE(FIRSTNONBLANK('Table'[Year],1),ALL('Table'))
VAR __Table = 
    ADDCOLUMNS(
        GROUPBY(
            'Table',
            [Year],
            "__MaxWeek",MAXX(CURRENTGROUP(),[Weeknum])
        ),
        "__Count",COUNTROWS(FILTER(ALL('Table'),'Table'[Year]=EARLIER([Year]) && 'Table'[Weeknum]=[__MaxWeek]))
    )
    VAR __Count = COUNTROWS(FILTER(__Table,[Year]<MyYear && [__Count] < 7))
    VAR __Count2 = COUNTROWS(FILTER('Table',[Year]=MyYear && [Weeknum]=1))
VAR myNum = 
    IF(
        MyYear=firstYear,
        [WeekNum],
        IF([Weeknum]>1 && __Count2 <> 7,
            [Weeknum]-1,
            MyStart+[Weeknum]-__Count
        )
    )
RETURN myNum

I have attached a PBIX file for you.

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

Can you explain with better example? If you are looking for Nonstandard periods, please refer

:

https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak ,

 

Plesae see below imagerevisionclmn.PNG

 

Hi @amaleranda 

Check Greg_Deckler's pbix, if his answer really helps you, please mark it as a solution so others may find the answers to this topic quicklly.

 

If not, please feel free to let me know.

 

Best Regards

Maggie

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors