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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Rolling value calculation

Hi,

 

I have the following question and would like to see if anyone can help. 

DateStore AStore B
Nov-212040
Dec-212040
Jan-222040
Feb-222040
Mar-222040

 

DateStoreSales
Nov-21A10
Dec-21B25
Jan-22A30
Feb-22A20
Mar-22A40

 

There are 2 set of data, if I select the timeframe Dec-21 to Feb-22, it will gives me the sum of Store A in table 1 within that period (20+20+20) divide the sum of Store A data in table 2 (30+20) = 1.2

 

So at the end I will need to have 2 measure one is for Store A and one is for Store B, to calulate the rolling value base on the timeline selected.

 

Thanks for the help!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated table.

Table =
CALENDAR(MIN('Table1'[Date]),MAX('Table1'[Date]))

vyangliumsft_0-1662537491999.png

2. Create measure.

MeasureA =
var _mindate=MINX(ALLSELECTED('Table'),[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),[Date])
return
DIVIDE(
SUMX(FILTER(ALL(Table1),
'Table1'[Date]>=_mindate&&'Table1'[Date]<=_maxdate),[StoreA]),
SUMX(
    FILTER(ALL(Table2),
    'Table2'[Date]>=_mindate&&'Table2'[Date]<=_maxdate&&'Table2'[Store]="A"),[Sales]))
MeasureB =
var _mindate=MINX(ALLSELECTED('Table'),[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),[Date])
return
DIVIDE(
SUMX(FILTER(ALL(Table1),
'Table1'[Date]>=_mindate&&'Table1'[Date]<=_maxdate),[StoreB]),
SUMX(
    FILTER(ALL(Table2),
    'Table2'[Date]>=_mindate&&'Table2'[Date]<=_maxdate&&'Table2'[Store]="B"),[Sales]))

3. Result:

vyangliumsft_1-1662537492002.png

 

If you need pbix, please click here.

Rolling value calculation.pbix

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated table.

Table =
CALENDAR(MIN('Table1'[Date]),MAX('Table1'[Date]))

vyangliumsft_0-1662537491999.png

2. Create measure.

MeasureA =
var _mindate=MINX(ALLSELECTED('Table'),[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),[Date])
return
DIVIDE(
SUMX(FILTER(ALL(Table1),
'Table1'[Date]>=_mindate&&'Table1'[Date]<=_maxdate),[StoreA]),
SUMX(
    FILTER(ALL(Table2),
    'Table2'[Date]>=_mindate&&'Table2'[Date]<=_maxdate&&'Table2'[Store]="A"),[Sales]))
MeasureB =
var _mindate=MINX(ALLSELECTED('Table'),[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),[Date])
return
DIVIDE(
SUMX(FILTER(ALL(Table1),
'Table1'[Date]>=_mindate&&'Table1'[Date]<=_maxdate),[StoreB]),
SUMX(
    FILTER(ALL(Table2),
    'Table2'[Date]>=_mindate&&'Table2'[Date]<=_maxdate&&'Table2'[Store]="B"),[Sales]))

3. Result:

vyangliumsft_1-1662537492002.png

 

If you need pbix, please click here.

Rolling value calculation.pbix

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Anonymous
Not applicable

Hi Yang,

 

Thanks for the quick response.

 

Jason123_0-1662539032641.png

The equation is working but if I visualize it in a line chart, it only show 1 result, is there any possibility that it can show also the cumulative trend from 2021 to 2022?

 

I tried to do this in excel as exmaple, not sure if it works in power BI

Jason123_1-1662539568660.png

 

Thank you.

amitchandak
Super User
Super User

@Anonymous , Create a common Date  table and then you can have measures like

 

Divide(Sum(Table1[StoreA]), calculate(Sum(Table2[Sales]), filter(Table2, table2[Store] ="A") ) )

 

Or you can unpivot first table have store there and common store table too

 

refer

https://amitchandak.medium.com/power-bi-when-i-asked-you-to-create-common-tables-a-quick-dax-solution-8e3eccb41bda

 

https://radacad.com/pivot-and-unpivot-with-power-bi

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hello,

 

Is there anyway not using common dates? Since my sales data contains a board range of dates and cannot suit into the store table.

 

Thank you.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.