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
DianaChris
Frequent Visitor

Counting number of records for last 6 periods excluding current period

Hi, I'm new to PowerBI and I've a requirement where I need to count number of records for 6 periods excluding current period. (1 period=4weeks) likewise for a financial year(April-March) we have 13 periods.

 

For example: if my current period is 4 then I need to exclude the number of records falling under dates of this current period and count 6 period backwards (ie. Period- {3,2,1,13,12,11}). In my table I've both date and period column. 

Can some one pls help me with the dax to solve this?

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @DianaChris ,

 

Here's my solution.

1.You could create a Period2 column which it is no cycle 1-13, but from 1 to calculate down.

Period2 = 
var _rank=RANKX('Calendar',[Date],,ASC,Dense)
return ROUNDUP(DIVIDE(_rank,28),0)

vstephenmsft_0-1656928481476.png

 

2.Then you can count number of records for last 6 periods excluding current period.

Measure = var _current=CALCULATE(MAX('Calendar'[Period2]),FILTER(ALL('Calendar'),[Date]=TODAY()))
return CALCULATE(COUNTROWS('Table'),FILTER(ALL('Calendar'),[Period2]>=_current-6&&[Period2]<_current))

vstephenmsft_2-1656928718065.png

 

 

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
DianaChris
Frequent Visitor

Thank you so much for the solution!

v-stephen-msft
Community Support
Community Support

Hi @DianaChris ,

 

Here's my solution.

1.You could create a Period2 column which it is no cycle 1-13, but from 1 to calculate down.

Period2 = 
var _rank=RANKX('Calendar',[Date],,ASC,Dense)
return ROUNDUP(DIVIDE(_rank,28),0)

vstephenmsft_0-1656928481476.png

 

2.Then you can count number of records for last 6 periods excluding current period.

Measure = var _current=CALCULATE(MAX('Calendar'[Period2]),FILTER(ALL('Calendar'),[Date]=TODAY()))
return CALCULATE(COUNTROWS('Table'),FILTER(ALL('Calendar'),[Period2]>=_current-6&&[Period2]<_current))

vstephenmsft_2-1656928718065.png

 

 

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.