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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. 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
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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