Forum Discussion
3 month rolling count
Hi,
I want to count the number of records based on the field. I have type and date tables that I do selection from those slicers. If I select 06.2020, I want to count the number of the records for 06,05,04.2020. I used the following measure, but it doesn't work:
type | dateselection | date | value |
a | 06.2020 | 06.04.2020 | 5 |
a | 06.2020 | 06.14.2020 | 21 |
a | 05.2020 | 05.04.2020 | 3 |
a | 03.2020 | 03.24.2020 | 8 |
a | 03.2020 | 03.04.2020 | 8 |
a | 02.2020 | 02.24.2020 | 9 |
b | 06.2020 | 06.04.2020 | 5 |
b | 06.2020 | 06.14.2020 | 21 |
b | 05.2020 | 05.04.2020 | 3 |
b | 04.2020 | 04.24.2020 | 8 |
b | 03.2020 | 03.04.2020 | 8 |
b | 02.2020 | 02.24.2020 | 3 |
b | 01.2020 | 01.24.2020 | 2 |
b | 01.2020 | 01.26.2020 | 2 |
| 06.2020 | 06.30.2020 |
| 05.2020 | 05.31.2020 |
| 04.2020 | 04.30.2020 |
| 03.2020 | 03.31.2020 |
| 02.2020 | 02.29.2020 |
| 01.2020 | 01.31.2020 |
| a |
| b |
Second issue: I want to count certain machines. If the difference between the end of the selected month and Main[date] is more than 5 days and less than 36 days, then that info should be counted. This is the second measure that I want to have.
Hi IF ,
Create 2 measures as below:
total moving count = CALCULATE(COUNTROWS('Main'),FILTER(ALL(Main),'Main'[dateselection]<=SELECTEDVALUE('Month'[Month])&&'Main'[dateselection]>=CALCULATE(MIN('Month'[Month]),DATEADD('Month'[Month],-2,MONTH))))selected type moving count = CALCULATE(COUNTROWS('Main'),FILTER(ALL(Main),'Main'[dateselection]<=SELECTEDVALUE('Month'[Month])&&'Main'[dateselection]>=CALCULATE(MIN('Month'[Month]),DATEADD('Month'[Month],-2,MONTH))&&'Main'[type]=SELECTEDVALUE('Type'[type])))And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
3 Replies
- timg
Solution Sage
Hi IF,
Regarding your first question, perhaps this logic will do?
MovingCount = CALCULATE ( COUNTROWS(FactSales), DATESINPERIOD ( DimDate[Date], LASTDATE ( DimDate[Date] ), -3, MONTH ) )This allows me to get the rolling record count of 3 months in my test set.
Hope it helps!
Regards,
Tim
- IF
Post Prodigy
Hi,
Thanks for your response!
I tried but didn't work for me. it brings data only for the selected month. I also want to count the values if they exist. It is possible that then it should not count.
Thanks again! Regards,
- v-kelly-msft
Community Support
Hi IF ,
Create 2 measures as below:
total moving count = CALCULATE(COUNTROWS('Main'),FILTER(ALL(Main),'Main'[dateselection]<=SELECTEDVALUE('Month'[Month])&&'Main'[dateselection]>=CALCULATE(MIN('Month'[Month]),DATEADD('Month'[Month],-2,MONTH))))selected type moving count = CALCULATE(COUNTROWS('Main'),FILTER(ALL(Main),'Main'[dateselection]<=SELECTEDVALUE('Month'[Month])&&'Main'[dateselection]>=CALCULATE(MIN('Month'[Month]),DATEADD('Month'[Month],-2,MONTH))&&'Main'[type]=SELECTEDVALUE('Type'[type])))And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!