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
JesperMadsen90
Regular Visitor

DATESINPERIOD All or Remove Filters

Hi!

 

I'm trying to calculate running 12 months total with the following measure:

 

MOVING TOTAL R12 =
        VAR OneYearBack =
            DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -1, YEAR )
        VAR Result =
            CALCULATE (
                VAR NumberOfMonths = COUNTROWS ( SUMMARIZE ( 'CRM Data', 'Date'[Year Month Number] ) )
                VAR NoOfCustomers = [No of Customer]
                VAR Result   = IF ( NumberOfMonths = 12, NoOfCustomers)
                RETURN
                    Result,
                OneYearBack
            )
        RETURN
            Result
 
Everything work fine except for that the measure can not stretch outside the months thats within my filtered table. Some sort of ALL formula seem to be needed. The result is accoring to below picture (table), the model contains data from 2019 but when I filter the table for 2020-2021 the "rolling 12 months measure" cannot get data from 2019.
 
JesperMadsen90_0-1675769256776.png

 

Is there some way to get the measure to include dates outside the filtered data within the DATESINPERIOD context?
 
2 ACCEPTED SOLUTIONS
v-tangjie-msft
Community Support
Community Support

Hi @JesperMadsen90 ,

 

Please this measure:

 

MOVING TOTAL R12 =
        VAR OneYearBack =
            Filter(ALL('Date'[Date]), [Date]<=MAX ( 'Date'[Date] )&&[Date]>=EDATE(MAX ( 'Date'[Date] ),-12))
        VAR Result =
            CALCULATE (
                VAR NumberOfMonths = COUNTROWS ( SUMMARIZE ( 'CRM Data', 'Date'[Year Month Number] ) )
                VAR NoOfCustomers = [No of Customer]
                VAR Result   = IF ( NumberOfMonths = 12, NoOfCustomers)
                RETURN
                    Result,
                OneYearBack
            )
        RETURN
            Result

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Thanks! I guess this measure will work as well. The solution was however very easy, the model had not connected my fact table to the date dimension table, creating the relationship solved everything.

View solution in original post

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @JesperMadsen90 ,

 

Please this measure:

 

MOVING TOTAL R12 =
        VAR OneYearBack =
            Filter(ALL('Date'[Date]), [Date]<=MAX ( 'Date'[Date] )&&[Date]>=EDATE(MAX ( 'Date'[Date] ),-12))
        VAR Result =
            CALCULATE (
                VAR NumberOfMonths = COUNTROWS ( SUMMARIZE ( 'CRM Data', 'Date'[Year Month Number] ) )
                VAR NoOfCustomers = [No of Customer]
                VAR Result   = IF ( NumberOfMonths = 12, NoOfCustomers)
                RETURN
                    Result,
                OneYearBack
            )
        RETURN
            Result

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Thanks! I guess this measure will work as well. The solution was however very easy, the model had not connected my fact table to the date dimension table, creating the relationship solved everything.

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 MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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