March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
I have the following formula that calculates the standard deviation of my last 7 days of sales:
Here are a couple of options:
1. A reasonably concise version, which applies a LASTDATE filter first, then applies 7 week range and Weekday filters within that:
7W StDev (current weekday) =
CALCULATE (
CALCULATE (
STDEVX.P ( 'Date Dim', CALCULATE ( SUM ( '--Sales'[sales_units] ) ) ),
DATESINPERIOD ( 'Date Dim'[Report Date], MAX ( 'Date Dim'[Report Date] ), -49, DAY ),
VALUES ( 'Date Dim'[Day of Week] ),
REMOVEFILTERS ( 'Date Dim' ) -- precaution
),
LASTDATE ( 'Date Dim'[Report Date] )
)
2. Similar structure to your existing measure
7W StDev (current weekday) =
VAR CurrentDateRow =
INDEX ( 1, 'Date Dim', ORDERBY ( 'Date Dim'[Report Date], DESC ) )
VAR CurrentDate =
SELECTCOLUMNS ( CurrentDateRow, 'Date Dim'[Report Date] )
VAR CurrentDayOfWeek =
SELECTCOLUMNS ( CurrentDateRow, 'Date Dim'[Day of Week] )
RETURN
STDEVX.P (
FILTER (
ALL ( 'Date Dim' ),
'Date Dim'[Report Date] >= CurrentDate - 48
&& 'Date Dim'[Report Date] <= CurrentDate
&& 'Date Dim'[Day of Week] = CurrentDayOfWeek
),
CALCULATE ( SUM ( '--Sales'[sales_units] ) )
)
3. Another alternative with STDEVX.P in CALCULATE:
7W StDev (current weekday) =
VAR CurrentDateRow =
INDEX ( 1, 'Date Dim', ORDERBY ( 'Date Dim'[Report Date], DESC ) )
-- Alternative:
-- TOPN ( 1, 'Date Dim', 'Date Dim'[Report Date] )
VAR CurrentDate =
SELECTCOLUMNS ( CurrentDateRow, 'Date Dim'[Report Date] )
VAR CurrentDayOfWeek =
SELECTCOLUMNS ( CurrentDateRow, 'Date Dim'[Day of Week] )
RETURN
CALCULATE (
STDEVX.P ( 'Date Dim', CALCULATE ( SUM ( '--Sales'[sales_units] ) ) ),
DATESINPERIOD ( 'Date Dim'[Report Date], CurrentDate, -49, DAY ), -- 49 day period ending on CurrentDate
CurrentDayOfWeek -- Apply CurrentDayOfWeek filter
)
Do any of these work for you?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
8 |
User | Count |
---|---|
37 | |
32 | |
21 | |
16 | |
14 |