Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Need help in calculating standard deviation using custom column

Dear All,

 

I would like to calcuate standard devation on below data using Custom column, please help I'm new to Power BI tool. Data looks like below

 

Source Data:

SiteCodeDAY_DATEDAYS
YPYPSL15204Jul2015 0:00:000
YPYPSL15212Jul2015 0:00:00-8
YPYPSL15210Aug2015 0:00:00-29
YPYPSL15212Dec2015 0:00:00-124
YPYPSL15214Dec2015 0:00:00-2
YPYPSL15217Jun2016 0:00:00-186
YPYPSL15219Dec2016 0:00:00-185
YPYPSL15222Dec2016 0:00:00-3
YPYPSL15221Feb2017 0:00:00-61
CGCG15511May2015 0:00:000
CGCG15511May2015 0:00:000
KBKB15518Dec2015 0:00:000
KBKB15514Feb2016 0:00:0058
KBKB15523Dec2016 0:00:00313
KBKB15520Dec2017 0:00:00362
KBKB15518Dec2015 0:00:000
KBKB15514Feb2016 0:00:00-58
KBKB15523Dec2016 0:00:00-313
KBKB15520Dec2017 0:00:00-362
FE 23Nov2017 0:00:000
FE 27Nov2017 0:00:004
FE 26Apr2018 0:00:00150
FE 23Nov2017 0:00:000
FE 27Nov2017 0:00:00-4
FE 26Apr2018 0:00:00-150

 

Expected Output:

SiteCodeSTD_OF_DAYS
YPYPSL152102.231571
CGCG1550
KBKB155257.6692232
FE 94.90205477

 

I have tried using Transform --> Statitistcs --> Standard Devatation which didn't worked for me. please guide mw how can i get expected out put as parked above.

 

In case of any more information required please do let me know, Thanks in advance for you help.

  • Hi Anonymous,

     

    Please try below Power Query.

    let
        Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data (Autosaved) (Autosaved).xlsx"), null, true),
        data_Sheet = Source{[Item="data",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(data_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Site", type text}, {"Code", type text}, {"DAY_DATE", type datetime}, {"DAYS", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Site", "Code"}, {{"standard deviation", each List.StandardDeviation([DAYS]), type number}})
    in
        #"Grouped Rows"

     

    Best regards,

    Yuliana Gu

6 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Tom & Stachu for your reply, I want same kind of logic to be done under query editor --> Custom Column because I need that result in a new column so that i can build rest of logic on top of it.

       

      Stachu - It's actual standard devation data source & Expected output which is implemented in diff tool which we are migrating in power bi.

      • Stachu's avatar
        Stachu
        Community Champion

        so you want to group the table with a new column calculating stadard deviation?

        one more question - is the output you showed based on exacly same dataset that you posted? When I calculate the standard deviation I get the same results as the ones that TomMartens has posted, which are not consistent with your outcome (see YP site)

  • Stachu's avatar
    Stachu
    Community Champion

    in PowerBI Modelling tab you can create this measure:
    STD_OF_DAYS = STDEV.P('Source Data'[DAYS])
    it gives values different than i your expected result- did you put dummy data there?

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi Anonymous,

     

    Please try below Power Query.

    let
        Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data (Autosaved) (Autosaved).xlsx"), null, true),
        data_Sheet = Source{[Item="data",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(data_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Site", type text}, {"Code", type text}, {"DAY_DATE", type datetime}, {"DAYS", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Site", "Code"}, {{"standard deviation", each List.StandardDeviation([DAYS]), type number}})
    in
        #"Grouped Rows"

     

    Best regards,

    Yuliana Gu