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
Hi,
Let me walk you through a better example. I am attempting to determine the most recent 6-Month STDEV for sales by product in order to determine variation.
The Sales Data is made up of daily transactions so it contains a fact_Sales[TransactionDate] and fact_Sales[units] (i.e. sales), but if there are no sales in a given month, then there will be no data for that month.
So, for example, on July 1st, sales for the past 6 months were the following:
Jan 100
Feb 125
Apr 140
May 125
Jun 130
March is missing because there were no sales. So, when I calculate STDEV on the data set, it is calculating it over 5 periods, when in fact there were 6, just one happend to be zero.
The code(Measure) I am curretly using is:
Instead of using date parameters in the code, I created a calculated column in the date table that gives each Month a unique ID, makes it easier for me.
What I need the formula to do is calculate STDEV across the six month period. If when pulling the monthly sales numbers, it only comes back with 3 periods, then it needs to assume the other 2 periods with a zero value.
Thank you for your help with this!!
Solved! Go to Solution.
@Bhanu_VA Maybe something like this, PBIX is attached below signature. I'm not getting your stated standard deviation values but I added a debugging measure into the PBIX that should help you determine what is going on. With the debugging measure you can see that it is returning 0's for empty months.
Measure StdDev =
VAR __Date = MAX('Table'[Date])
VAR __BeginDate = EOMONTH(__Date,-6)
VAR __EndDate = EOMONTH(__Date, -1)
VAR __Table = FILTER(ALL('Table'),[Date]>=__BeginDate && [Date]<=__EndDate)
VAR __Count = COUNTROWS(__Table)
VAR __Missing = 6 - __Count
VAR __MissingTable =
SELECTCOLUMNS(
ADDCOLUMNS(
GENERATESERIES(1,__Missing,1),
"rmv",0
),
"rmv",[rmv],
"Date",[Value]
)
VAR __FinalTable = UNION(__Table, __MissingTable)
VAR __Result = STDEVX.P(__FinalTable,[rmv])
RETURN
__Result
@Bhanu_VA Maybe something like this, PBIX is attached below signature. I'm not getting your stated standard deviation values but I added a debugging measure into the PBIX that should help you determine what is going on. With the debugging measure you can see that it is returning 0's for empty months.
Measure StdDev =
VAR __Date = MAX('Table'[Date])
VAR __BeginDate = EOMONTH(__Date,-6)
VAR __EndDate = EOMONTH(__Date, -1)
VAR __Table = FILTER(ALL('Table'),[Date]>=__BeginDate && [Date]<=__EndDate)
VAR __Count = COUNTROWS(__Table)
VAR __Missing = 6 - __Count
VAR __MissingTable =
SELECTCOLUMNS(
ADDCOLUMNS(
GENERATESERIES(1,__Missing,1),
"rmv",0
),
"rmv",[rmv],
"Date",[Value]
)
VAR __FinalTable = UNION(__Table, __MissingTable)
VAR __Result = STDEVX.P(__FinalTable,[rmv])
RETURN
__Result
Thanks @Greg_Deckler ,
Apologies for making things difficult for you @Greg_Deckler . I don't see any option to upload the sample file. There is a bit change in dataset and sorry for that.
when I calculated Standard Deviation Manually for the past 21 Months(Dec 2017 selected in the Slicer) I got the Standard Deviation as 0.94.
Note: I think I can't afford to create a calculated table, the table is transactional table it's keep growing.
Thanks
@Bhanu_VA I didn't create a calculated table, just a measure. You can share a PBIX file on something like OneDrive or Box and post a link here.
Hi @Greg_Deckler ,
Here is the sample pbix. Please select sep 2022(in the slicer), so that we will have enough data. https://1drv.ms/u/s!AlFPrnIF0lWCfNoRDLODUZdzBvs?e=ruT6bi
Thanks
@Bhanu_VA So the Data table should be this?
Date | rmv |
Jun-20 | 3 |
Sep-20 | 13 |
Oct-20 | 1 |
Nov-20 | 5 |
Dec-20 | 7 |
Jan-21 | 6 |
Feb-21 | 3 |
Mar-21 | 4 |
Apr-21 | 7 |
May-21 | 1 |
Jun-21 | 4 |
Jul-21 | 3 |
Aug-21 | 1 |
Sep-21 | 2 |
Oct-21 | 1 |
Nov-21 | 1 |
Dec-21 | 4 |
Jan-22 | 7 |
Hi @Greg_Deckler .
The below link(has pbix) has perfect my kind of scenario. https://1drv.ms/u/s!AlFPrnIF0lWCfNoRDLODUZdzBvs?e=ruT6bi
Thanks
Hi @Greg_Deckler ,
Any luck with the pbix file I had shared. Tried many ways, nothing worked.
Thanks
Hi @Greg_Deckler ,
Unfortunately, I can't share my work ondrive link over here, If possible could you please use with the above pasted data.
sorry for the trouble.
Thanks
@Bhanu_VA The problem with what you shared is I don't see any data to take a standard deviation of. What am I missing?
Hi,
Sorry, unable to upload pbix file, pasting the values below.
Note: I need Standard Deviation for 21 months from which ever date I select. In current scenario selected date is Jan-22
Date | rmv |
Jun-20 | 3 |
Sep-20 | 13 |
Oct-20 | 1 |
Nov-20 | 5 |
Dec-20 | 7 |
Jan-21 | 6 |
Feb-21 | 3 |
Mar-21 | 4 |
Apr-21 | 7 |
May-21 | 1 |
Jun-21 | 4 |
Jul-21 | 3 |
Aug-21 | 1 |
Sep-21 | 2 |
Oct-21 | 1 |
Nov-21 | 1 |
Dec-21 | 4 |
Jan-22 | 7 |
for the month of Jan-22, I had calculated Standard Deviation manually and '3.17' as result.
I used calendar table as well.
Try
Standard Dev prev 6 months =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR StartDate =
EOMONTH ( MaxDate, -7 ) + 1
VAR DatesToUse =
CALCULATETABLE (
VALUES ( 'Date'[Year month] ),
DATESBETWEEN ( 'Date'[Date], StartDate, MaxDate )
)
VAR Result =
STDEVX.P ( DatesToUse, COALESCE ( [Sum of sales], 0 ) )
RETURN
Result
This assumes that you are including dates in the visual. If you just want to show data as at today then set a visual level filter so that the date is today.
Hi,
Thanks for replying
I tried same query with different month number {EOMONTH (MaxDate, -7)+1} and for all of them the result is 0.
Could you please share pbix file.
Thanks
can you share some sample data ?
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 |
---|---|
129 | |
90 | |
75 | |
58 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |