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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
dtataev
New Member

Calculate data in the period in the past with a delay

How to calculate in DAX( or another way in Powerbi) the "count of loans" that were received in the period between 6 and 18 months from the selected month?

For example, if I select June 2022, I wan to see  how many loans were received in the period between 6 and 18 months before that.( In this case, it would be the full year of 2021), and if I would select another month, then the calculation would shift accordingly.

 

I have a dates table, and table with Loans and received dates for them for simplicity. 

 

Would you be able to share any ideas? I could not find a working solution. 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @dtataev ,

I created some data:

Table:

vyangliumsft_2-1680855712520.png

Date:

vyangliumsft_3-1680855712520.png

 

Here are the steps you can follow:

1. Create calculated column.

month_year =
FORMAT(
    'Date'[Date],"mmmm")&" "&YEAR('Date'[Date])
Rank =
RANKX(
       ALL('Date'),'Date'[Date],,ASC)

vyangliumsft_4-1680855732531.png

2. Create calculated table.

Slicer =
SUMMARIZE(
    'Date',
    'Date'[month_year],"Index",
    MINX(
        FILTER(ALL('Date'),
        'Date'[month_year]=EARLIER('Date'[month_year])),[Rank]))

vyangliumsft_5-1680855755005.png

3. [month_year] – Column tools – Sort by column – [Index]

vyangliumsft_6-1680855782368.png

4. Create measure.

Flag =
var _select=
SELECTEDVALUE(Slicer[month_year])
var _maxdate=
EOMONTH(
MAXX(
    FILTER(ALL('Date'),'Date'[month_year]=_select),[Date]),0)
var _6Month=
EOMONTH(_maxdate,-6)
var _18month=
EOMONTH(
    _maxdate,-18)
var _first18month=
DATE(
    YEAR(_18month),MONTH(_18month),1)
return
IF(
    MAX('Table'[Date]) >= _first18month&& MAX('Table'[Date]) <=_6Month,1,0)
Value_all =
SUMX(
    ALLSELECTED('Table'),[Value])

 5. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_7-1680855858309.png

6. Result:

vyangliumsft_8-1680855872936.png

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi  @dtataev ,

I created some data:

Table:

vyangliumsft_2-1680855712520.png

Date:

vyangliumsft_3-1680855712520.png

 

Here are the steps you can follow:

1. Create calculated column.

month_year =
FORMAT(
    'Date'[Date],"mmmm")&" "&YEAR('Date'[Date])
Rank =
RANKX(
       ALL('Date'),'Date'[Date],,ASC)

vyangliumsft_4-1680855732531.png

2. Create calculated table.

Slicer =
SUMMARIZE(
    'Date',
    'Date'[month_year],"Index",
    MINX(
        FILTER(ALL('Date'),
        'Date'[month_year]=EARLIER('Date'[month_year])),[Rank]))

vyangliumsft_5-1680855755005.png

3. [month_year] – Column tools – Sort by column – [Index]

vyangliumsft_6-1680855782368.png

4. Create measure.

Flag =
var _select=
SELECTEDVALUE(Slicer[month_year])
var _maxdate=
EOMONTH(
MAXX(
    FILTER(ALL('Date'),'Date'[month_year]=_select),[Date]),0)
var _6Month=
EOMONTH(_maxdate,-6)
var _18month=
EOMONTH(
    _maxdate,-18)
var _first18month=
DATE(
    YEAR(_18month),MONTH(_18month),1)
return
IF(
    MAX('Table'[Date]) >= _first18month&& MAX('Table'[Date]) <=_6Month,1,0)
Value_all =
SUMX(
    ALLSELECTED('Table'),[Value])

 5. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_7-1680855858309.png

6. Result:

vyangliumsft_8-1680855872936.png

 

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

amitchandak
Super User
Super User

@dtataev , Try a measure with help from date table

 

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],eomonth(MAX('Date'[Date]),-6) ,-12,MONTH))

 

Rolling Months Formula: https://youtu.be/GS5O4G81fww

 

You can also consider window function

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

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

Thank you, it worked if I select June 2022, it shows data for the whole year of 2022. BUT it doesn't work if I select May or any other month. The numbers do not sum correctly ( more than there should be).

How can it be?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors