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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
raassd
Helper I
Helper I

New column where it gives same output for each 7 rows

Hi Team,

 

I have 700 rows of data which is basically date column, I have to create a new column where it gives output as 1 for 1st 7 rows and followed by 2 for next 7 rows and goes on till 52 and after that it should again start from 1.

raassd_0-1722510318960.png

Thanks

1 ACCEPTED SOLUTION

@raassd Sorry, missed that. This should work:

WeekNum = 
    VAR __Count = COUNTROWS( FILTER( 'Dates', [Date] <= EARLIER( 'Dates'[Date] ) ) )
    VAR __Num = INT( DIVIDE( __Count , 7 ) )
    VAR __WeekNum = IF( MOD( __Count, 7 ) = 0, __Num, __Num + 1 )
    VAR __Result = IF( __WeekNum > 52, __WeekNum - 52 * ( INT( DIVIDE( __WeekNum, 52 ) ) ), __WeekNum )
RETURN
    __Result


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

3 REPLIES 3
Greg_Deckler
Super User
Super User

@raassd Try this:

WeekNum = 
    VAR __Count = COUNTROWS( FILTER( 'Dates', [Date] <= EARLIER( 'Dates'[Date] ) ) )
    VAR __Num = INT( DIVIDE( __Count , 7 ) )
    VAR __Result = IF( MOD( __Count, 7 ) = 0, __Num, __Num + 1 )
RETURN
    __Result


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...

@Greg_Deckler ,

Thanks for the response !

Here is my output, I am getting 53 and 54 so but my requirment is after 52 it should start again from 1.

raassd_0-1722514002580.png

 

Thanks again!

 

@raassd Sorry, missed that. This should work:

WeekNum = 
    VAR __Count = COUNTROWS( FILTER( 'Dates', [Date] <= EARLIER( 'Dates'[Date] ) ) )
    VAR __Num = INT( DIVIDE( __Count , 7 ) )
    VAR __WeekNum = IF( MOD( __Count, 7 ) = 0, __Num, __Num + 1 )
    VAR __Result = IF( __WeekNum > 52, __WeekNum - 52 * ( INT( DIVIDE( __WeekNum, 52 ) ) ), __WeekNum )
RETURN
    __Result


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...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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