Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

find the rolling difference between 2 different (not earlier one) rows on the same column.

I need to find the difference of values of the current week and the value of 13 months apart in power bi.  

Subtracting the current order quantity Value and the value 13 year before value (and create a running subtraction) based on the calendar.  

 

Calendar yearOrder quantity
5/30/2022478
5/23/2022511
5/16/202258
5/9/2022194
5/2/202261
4/25/202281
4/18/2022203
4/11/2022125
4/4/202256
3/28/202255
3/28/202280
3/21/202285
3/14/2022165
3/7/202290
2/28/202221
2/28/20224
2/21/202292
2/14/2022110
2/7/202251
1/31/202273
1/31/202249
1/24/202272
1/17/202286
1/10/202267
1/3/202262
12/27/2021633
12/20/2021138
12/13/202160
12/6/202169
11/29/202160
11/29/2021104
11/22/2021519
11/15/2021124
11/8/2021139
11/1/2021164
10/25/202131
10/18/2021149
10/11/2021113
10/4/202195
9/27/20218
9/27/202122
9/20/2021212
9/13/2021565
9/6/2021194
8/30/202127
8/30/2021619
8/23/202188
8/16/202180
8/9/202179
8/2/2021552
7/26/202177
7/19/202180
7/12/202119
7/5/202169
6/28/202127
6/28/202158
6/21/202157
6/14/2021231
6/7/2021482
5/31/202141
5/31/202129
5/24/202156
5/17/202123
5/10/2021254
5/3/202144
4/26/202136
4/19/2021770
4/12/202192
4/5/202128
3/29/202128
3/29/2021142
3/22/202170
3/15/2021121
3/8/2021219
3/1/2021120
2/22/202138
2/15/2021104
2/8/2021211
2/1/2021108
1/25/2021392
1/18/2021453
1/11/202139
12/21/2020117
12/14/2020170
12/7/2020225
11/30/202084
11/30/202016
11/23/2020217
11/16/202099
11/9/202061
11/2/202025
10/26/2020138
10/19/2020427
10/12/202038
10/5/2020162
9/28/2020132
9/28/2020125
9/21/2020288
9/14/202051
9/7/202058
8/31/202063
8/31/2020107
8/24/2020248
8/17/202071
8/10/2020743
8/3/2020111
7/27/2020387
7/20/2020106
7/13/202054
7/6/2020333
6/29/2020255
6/29/202022
6/22/202013
6/15/2020324
6/8/2020196
6/1/202050
5/25/2020255
5/18/202085
5/11/2020142
5/4/2020102

 

The result should look like this: 

subtracting orderquantity colum in different rows :

478(b2)- 81(b26)= 416  

511(b3)-633(b27) =-122

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You can add a new index column to the PowerQuery Eidtor.

vcgaomsft_0-1657162244351.png

Then create a calculated column.

Column = 
VAR _order = 'Table'[Order quantity]
VAR _index_subtract = 'Table'[Index] + 52
VAR _subtract =
    CALCULATE (
        MAX ( 'Table'[Subtract] ),
        FILTER ( 'Table', 'Table'[Index] = _index_subtract )
    )
VAR _result = _order - _subtract
RETURN
    _result

vcgaomsft_1-1657162294903.png

The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

5 REPLIES 5
v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

//The result should look like this: 

subtracting orderquantity colum in different rows :

478(b2)- 81(b26)= 416  

511(b3)-633(b27) =-122

 

vcgaomsft_0-1656663297219.png

It seems that the expected output is not calculated according to the rules described above, would you mind explaining again how it is calculated or checking the expected output for a typo? Thanks in advance.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Anonymous
Not applicable

Here is what the result should look like in excel-  @v-cgao-msft @amitchandak . Please ignore the earlier resluts. 

the formula for the Subtract colum in excel is

Row 1= C2 - C54

Row 2= C3 - C55
Row 3= C4 - C56

Calendar yearOrder quantitySubtract
5/30/2022478459
5/23/2022511442
5/16/20225831
5/9/2022194136
5/2/2022614
4/25/202281-150
4/18/2022203-279
4/11/202212584
4/4/20225627
3/28/202255-1
3/28/20228057
3/21/202285-169
3/14/2022165121
3/7/20229054
2/28/202221-749
2/28/20224-88
2/21/20229264
2/14/202211082
2/7/202251-91
1/31/2022733
1/31/202249-72
1/24/202272-147
1/17/202286-34
1/10/20226729
1/3/202262-42
12/27/2021633422
12/20/202113830
12/13/202160-332
12/6/202169-384
11/29/20216021
11/29/2021104-13
11/22/2021519349
11/15/2021124-101
11/8/202113955
11/1/2021164148
10/25/202131-186
10/18/202114950
10/11/202111352
10/4/20219570
9/27/20218-130
9/27/202122-405
9/20/2021212174
9/13/2021565403
9/6/202119462
8/30/202127-98
8/30/2021619331
8/23/20218837
8/16/20218022
8/9/20217916
8/2/2021552445
7/26/202177-171
7/19/2021809
7/12/202119-724
7/5/202169-42
6/28/202127-360
6/28/202158-48
6/21/2021573
6/14/2021231-102
6/7/2021482227
5/31/20214119
5/31/20212916
5/24/202156-268
5/17/202123-173
5/10/2021254204
5/3/202144-211
4/26/202136-49
4/19/2021770628
4/12/202192-10
4/5/20212828
3/29/20212828
3/29/2021142142
3/22/20217070
3/15/2021121121
3/8/2021219219
3/1/2021120120
2/22/20213838
2/15/2021104104
2/8/2021211211
2/1/2021108108
1/25/2021392392
1/18/2021453453
1/11/20213939
12/21/2020117117
12/14/2020170170
12/7/2020225225
11/30/20208484
11/30/20201616
11/23/2020217217
11/16/20209999
11/9/20206161
11/2/20202525
10/26/2020138138
10/19/2020427427
10/12/20203838
10/5/2020162162
9/28/2020132132
9/28/2020125125
9/21/2020288288
9/14/20205151
9/7/20205858
8/31/20206363
8/31/2020107107
8/24/2020248248
8/17/20207171
8/10/2020743743
8/3/2020111111
7/27/2020387387
7/20/2020106106
7/13/20205454
7/6/2020333333
6/29/2020255255
6/29/20202222
6/22/20201313
6/15/2020324324
6/8/2020196196
6/1/20205050
5/25/2020255255
5/18/20208585
5/11/2020142142
5/4/2020102102

Hi @Anonymous ,

 

You can add a new index column to the PowerQuery Eidtor.

vcgaomsft_0-1657162244351.png

Then create a calculated column.

Column = 
VAR _order = 'Table'[Order quantity]
VAR _index_subtract = 'Table'[Index] + 52
VAR _subtract =
    CALCULATE (
        MAX ( 'Table'[Subtract] ),
        FILTER ( 'Table', 'Table'[Index] = _index_subtract )
    )
VAR _result = _order - _subtract
RETURN
    _result

vcgaomsft_1-1657162294903.png

The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Anonymous
Not applicable

Hi sorry, for the late reply, I did not see this on time.

I wanted to subtract values from different rows in same column. I am subtracting order quantity by date by 52 weeks apart. And please dont do it on 13 months. Do it on weekly basis, which is 52 weeks.

 

Max Date is the first one and you will subtract it  with a value 52 weeks later value.

 

I will update the question. Please Thanks in advance. Let me know if you need something else.  

 

 

 

amitchandak
Super User
Super User

@Anonymous , what I can see is 24-week part.

 

With help from week Rank, Prefer a separate week or date table

 

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))

 

24 the Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-24))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.