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

61/5000 Average sales for the last 3 days excluding Sundays

Hello,

 

I have a problem with a calculated measure for the average sales for the last 3 days BUT excluding Sundays and considering the previous days for that. I have the next formula:

 

AVG_SALES = (DIVIDE(CALCULATE(SUM(sales);DATESINPERIOD(date;LASTDATE(date);-3;DAY));3))

 

And that give the next result:

First result.png

 

But my expect result is:

Expect result.png

 

For days near to Sunday, the result is different. For example, for Sunday I average 1150+1200+800 excluding Sunday. For Monday, I average 1500+800+1200 excluding Sunday and Finally, in Tuesday I average 1230+1500+800.

 

I await your comments to help me with this measure. Thank you very much

 

Arturo Castillo

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @arturocastillo,

 

Based on my test, the formula below should work in your scenario. Smiley Happy

AVG_SALES = 
VAR currentDate =
    MAX ( Table1[Date] )
VAR currentWeekDay =
    WEEKDAY ( currentDate, 1 )
RETURN
    IF (
        currentWeekDay > 3,
        DIVIDE (
            CALCULATE (
                SUM ( Table1[Sales] ),
                FILTER (
                    ALL ( Table1 ),
                    currentDate - Table1[Date]
                        < 3
                        && currentDate - Table1[Date]
                        >= 0
                )
            ),
            3
        ),
        DIVIDE (
            CALCULATE (
                SUM ( Table1[Sales] ),
                FILTER (
                    ALL ( Table1 ),
                    currentDate - Table1[Date]
                        < 4
                        && currentDate - Table1[Date]
                        >= 0
                        && WEEKDAY ( Table1[Date], 1 ) <> 1
                )
            ),
            3
        )
    )

r2.PNG

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Employee
Employee

Hi @arturocastillo,

 

Based on my test, the formula below should work in your scenario. Smiley Happy

AVG_SALES = 
VAR currentDate =
    MAX ( Table1[Date] )
VAR currentWeekDay =
    WEEKDAY ( currentDate, 1 )
RETURN
    IF (
        currentWeekDay > 3,
        DIVIDE (
            CALCULATE (
                SUM ( Table1[Sales] ),
                FILTER (
                    ALL ( Table1 ),
                    currentDate - Table1[Date]
                        < 3
                        && currentDate - Table1[Date]
                        >= 0
                )
            ),
            3
        ),
        DIVIDE (
            CALCULATE (
                SUM ( Table1[Sales] ),
                FILTER (
                    ALL ( Table1 ),
                    currentDate - Table1[Date]
                        < 4
                        && currentDate - Table1[Date]
                        >= 0
                        && WEEKDAY ( Table1[Date], 1 ) <> 1
                )
            ),
            3
        )
    )

r2.PNG

 

Regards

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.

Top Solution Authors