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

5 Day Rolling Period With Multiple Days Selected

Hi guys.

I am trying to display values for a 5 day rolling period for data that has a value (AA, BB or CC). I calculated the 5-day rolling sum using:

AA Rolling 5 day = CALCULATE(SUM('Dashboard'[AA]),
FILTER( ALL('Dashboard'[transDate]),
'Dashboard'[transDate]>=MAX('Dashboard'[transDate])-5
&& 'Dashboard'[transDate]<=MAX('Dashboard'[transDate])))
I wish the be able to get the total without having the manually select multiple dates. So if I select a day, then results for the previous 5 days must appear. 
I have attached a picture.Capture.PNG
 
 

 

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

Hi,

 

According to your description, i create a sample to test:

120.PNG

Then create a seperate date slicer table:

 

DateSlicer = DISTINCT(SELECTCOLUMNS('Table',"Date",'Table'[transDate]))

 

Create a new category table by Enter Data:

121.PNG

Then try this measure:

 

Measure = 
SWITCH (
    SELECTEDVALUE ( 'New Category'[New Category] ),
    "AA Rolling 5 Day", CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[Category] = "AA"
                && 'Table'[transDate]
                    >= SELECTEDVALUE ( DateSlicer[Date] ) - 5
                && 'Table'[transDate] <= SELECTEDVALUE ( DateSlicer[Date] )
        )
    ),
    "BB Rolling 5 Day", CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[Category] = "BB"
                && 'Table'[transDate]
                    >= SELECTEDVALUE ( DateSlicer[Date] ) - 5
                && 'Table'[transDate] <= SELECTEDVALUE ( DateSlicer[Date] )
        )
    ),
    "CC Rolling 5 Day", CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[Category] = "CC"
                && 'Table'[transDate]
                    >= SELECTEDVALUE ( DateSlicer[Date] ) - 5
                && 'Table'[transDate] <= SELECTEDVALUE ( DateSlicer[Date] )
        )
    )
)

 

When you select one value in seperate date slicer, it shows:

122.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

View solution in original post

3 REPLIES 3
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, i create a sample to test:

120.PNG

Then create a seperate date slicer table:

 

DateSlicer = DISTINCT(SELECTCOLUMNS('Table',"Date",'Table'[transDate]))

 

Create a new category table by Enter Data:

121.PNG

Then try this measure:

 

Measure = 
SWITCH (
    SELECTEDVALUE ( 'New Category'[New Category] ),
    "AA Rolling 5 Day", CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[Category] = "AA"
                && 'Table'[transDate]
                    >= SELECTEDVALUE ( DateSlicer[Date] ) - 5
                && 'Table'[transDate] <= SELECTEDVALUE ( DateSlicer[Date] )
        )
    ),
    "BB Rolling 5 Day", CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[Category] = "BB"
                && 'Table'[transDate]
                    >= SELECTEDVALUE ( DateSlicer[Date] ) - 5
                && 'Table'[transDate] <= SELECTEDVALUE ( DateSlicer[Date] )
        )
    ),
    "CC Rolling 5 Day", CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[Category] = "CC"
                && 'Table'[transDate]
                    >= SELECTEDVALUE ( DateSlicer[Date] ) - 5
                && 'Table'[transDate] <= SELECTEDVALUE ( DateSlicer[Date] )
        )
    )
)

 

When you select one value in seperate date slicer, it shows:

122.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

Thank you so much @v-gizhi-msft .

 

How do I get the row total?

It is coming up blank.

Pragati11
Super User
Super User

HI @sthandiwe ,

 

There is already a thread for similar kind of issue as follows:

https://community.powerbi.com/t5/Desktop/Rolling-5-days-back/m-p/827160

 

try modifying your DAX expression to the one mentioned in this thread.

 

If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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.