cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Pongpon
Regular Visitor

Calculate row step like Excel

Hi Community, 

 

I want to calculate data in Power Query like Excel example. I tried many ways but failed. 

 

Value,

Pongpon_4-1628480831985.png

 

 

Formular,

Pongpon_5-1628480847667.png

 

Thank you.

 

 

3 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

ziying35
Impactful Individual
Impactful Individual

try this:

// output
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    acc = List.Accumulate(
               Source[Column1], 
               {null, {}}, 
               (s,c)=>let n=s{0}??List.Sum(Source[Column1]) 
                      in {n*2.32+c-n, s{1}&{{c, n, n*2.32, n*2.32+c, n*2.32+c-n}}}
          ),
    result = Table.TransformColumns(#table(null, acc{1}), {}, each Number.Round(_, 2))
in
    result

View solution in original post

11 REPLIES 11
ziying35
Impactful Individual
Impactful Individual

try this:

// output
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    acc = List.Accumulate(
               Source[Column1], 
               {null, {}}, 
               (s,c)=>let n=s{0}??List.Sum(Source[Column1]) 
                      in {n*2.32+c-n, s{1}&{{c, n, n*2.32, n*2.32+c, n*2.32+c-n}}}
          ),
    result = Table.TransformColumns(#table(null, acc{1}), {}, each Number.Round(_, 2))
in
    result

View solution in original post

Thank you.

wdx223_Daniel
Super User
Super User

Hi, thank you for the help me.

I try add column number for calculate.

But the data is retrieved only for the first column.

Pongpon_2-1628857675929.png

 

Pongpon_0-1628857274358.png

Calculate like this

Pongpon_0-1629129226735.png

 

Thank you.

I want to add group in data like this, 

Pongpon_0-1628507820949.png

How to edit code?

Thank you.

Thank you very much.

Thank you!

But i put same code in Power Query for Power BI, Not work.

Pongpon_1-1628497034520.png

 

your column1 is text, it should be number

Thank you, you have my life. 😊

Great, Can you send .pbix file to my email. (namphon.chailungka@gmail.com)
Thank you so much.

Helpful resources

Announcements
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors