Skip to main content

Hi,

Imagine a table of sales data with each row containing the sales date and the amount sold.

My goal is to calculate the standard deviation of monthly sales (and use this value in other formulas).

 

Getting the monthly sales is easy:

DIM: ROUND_MONTH(SALES.DATE), KPI: SUM(SALES.AMOUNT)

 

In order to STDEV over those monthly values, I thought about doing the monthly sum within a PU function like so:

 

PU_SUM(DOMAIN_TABLE(ROUND_MONTH(SALES.DATE)), SALES.AMOUNT))

 

In my understanding of PU functions, I would've thought that this results in the same values as DIM: ROUND_MONTH(SALES.DATE), KPI: SUM(SALES.AMOUNT).

 

But it does not, the values are roughly 10 times as high, each "month" is higher than the sum of all amounts together.

 

In the end I want to be able to use a formula to get the STDEV and use this to calculate other KPIs

 

Thanks in advance

Hello,

Thank you for your patience. While investigating this case I created dummy data to mirror your sales data (one date column one column with dollar amounts) and loaded it into the EMS. In an analysis I created a simple OLAP table with the dimension column being: "MONTH( "Sample_sales_xlsx_Sheet1"."DATE" )" and the KPI column was: "STDEV ( "Sample_sales_xlsx_Sheet1"."AMOUNT" )" . Doing this returned the correct standard deviations for the generated dummy data. I hope this will be helpful but if the issue still persists please let us know!

Best,
Sutton Coyle

Hi,

thanks for the answer.

 

With your "code" I get the standard deviation for sales within each month, but what I'd like to have is the standard deviation of the monthly sales data.

 

Let's assume the following data

 

Date Amount

02/05/2022 200

02/28/2022 300

03/01/2022 100

03/23/2022 200

04/15/2022 300

04/18/2022 300

 

We then have monthly sales amounts of 500, 300 and 600 for February, March and April respectively.

I want to have the standard deviation of those values, which according to Excel is 152.75.

 

I might also need to limit the months I calculate the standard deviation of. E.g. calculate the standard deviation of the monthly sales for this year and compare it to the standard deviation of last years monthly sales.

 

We resorted to creating extra tables in SQL since we didn't manage to do this in PQL.

 

But maybe you can show me how it can/should be done.

 

Regards,

Tobi

 


Reply