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
ak77
Post Patron
Post Patron

calculate row count of each year of rolling return years

Hi All,
 
i hve the below requirement, please check. i have below large dataset with following columns from 2010 till date.some code has data daily wise(365 rows per year) 
and some both monthly and daily  data (12 and 365 rows per year) 
Code,Class name, returns, Date
 
i am calculating rolling periods( 1 year, 2year till 10 year as below pic) for each code and date selected(Only month end date selection) and its working fine.
ak77_0-1696026863075.png

 

 
My client is asking me to calculate rolling periods if the rowcount matches 365/year for day wise data and 12/year for monthly data.
for ex: for Code 1  from 2022 its daily data and before 2022 ->Monthly data
For 31-dec-2022 and Code 1 selected
1 year(2022)-> check for 365 rows for 2022 year
2 yr 2022,2021 check for 365 rows for 2022 year+ check for 12 rows for 2021 year
3 yr 2022,2021,2020 check for 365 rows for 2022 year+ check for 12 rows for 2021 year+ check for 12 rows for 2020 year
 
if the rowcount matches then calculate sum of all selected years else display blank.
 
Please help
 
How to use a generic way condition to implement this rule
1 REPLY 1
amitchandak
Super User
Super User

@ak77 , Using date table you can create measures like 

 

Rolling 1 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-1,Year))

 

Rolling 1  = CALCULATE([Net], WINDOW(-11,REL, 0, REL, ADDCOLUMNS(ALLSELECTED('Date'[Month Year],'Date'[Month Year Sort] ),ORDERBY([Month Year Sort],asc)))

 

or

 

Rolling 2 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-2,Year))

 

Rolling 2  = CALCULATE([Net], WINDOW(-23,REL, 0, REL, ADDCOLUMNS(ALLSELECTED('Date'[Month Year],'Date'[Month Year Sort] ),ORDERBY([Month Year Sort],asc)))

 

Create all measures, and if needed add them to calculation groups 

 

 

 

Continue to explore Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc
https://medium.com/@amitchandak/power-bi-window-function-3d98a5b0e07f

 

Calculation Groups- Measure Slicer, Measure Header Grouping, Measure to dimension conversion. Complex Table display : https://youtu.be/qMNv67P8Go0

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

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.