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
kuldeepjain
Frequent Visitor

DATEINPERIOD with Two column to pass in DAX for rolling SUM

The situation is to find a rolling sum of the last 12 months for a date column but also need to use another column to get the final range of valid dates to pass in a variable. (rolling sum for overlapping date range from two data columns in a table)

 

Apologies for cross-posting as it seems that on this forum I can get quick help. https://chandoo.org/forum/threads/dateinperiod-with-two-column-to-pass-in-dax-for-rolling-sum.50610/...

The first code works well for calculating rolling SUM for the last 12 months. 

 

LTFail-Communication = VAR NumOfMonths = 12
VAR LTFailCutoff = LOOKUPVALUE(
    FailureData_ICF_Trend[ProductMaster.CutOffWarrenty],
    FailureData_ICF_Trend[ProductMaster.prod221],"COMMUNICATION"
                              )
VAR LastCurrentDate =EOMONTH(
    MAX (FailureData_ICF_Trend[repairmonth]),0)
VAR Period =
    DATESINPERIOD ( 'Calender'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
      SUMX(
        VALUES ('Calender'[Date]), FailureData_ICF_Trend[FailQty_Trend]),Period,
                FailureData_ICF_Trend[ProductMaster.prod221]= "COMMUNICATION"
              )
VAR FirstDateInPeriod = MINX ( Period, 'Calender'[Date] )
VAR LastDateWithSales = EOMONTH(MAX ( FailureData_ICF_Trend[repairmonth] ),0)
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

 

Now another filter of a different date column is also required so i tried to modify this to use another dateinperiod to get the final valid data range. I am not able to figure out how to use the new VAR Period 1 in the Result variable along with the existing period. Basically, it's like putting sumifs in Excel for Period Variable

 

LTFail-ToDeleteOriginal = VAR NumOfMonths = 12
VAR LTFailCutoff = LOOKUPVALUE(
    FailureData_ICF_Trend[ProductMaster.Life Warrenty.years],
    FailureData_ICF_Trend[ProductMaster.prod221],"COMMUNICATION"
                              )
VAR LastCurrentDate =EOMONTH(
    MAX (FailureData_ICF_Trend[repairmonth]),0)
VAR LastCurrentDateInvoice =EOMONTH(
    MAX (ShipmentData_ICF_T[invoicemonth]),0)
VAR Period =
    DATESINPERIOD ( 'Calender'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Period1 = DATESINPERIOD ( 'CalenderRepairCutoff'[Date], LastCurrentDateInvoice, - LTFailCutoff, YEAR )
VAR Result =
    CALCULATE (
      SUMX(
        VALUES ('Calender'[Date]), FailureData_ICF_Trend[FailQty_Trend]),Period,
                FailureData_ICF_Trend[ProductMaster.prod221]= "COMMUNICATION",
              )
VAR FirstDateInPeriod = MINX ( Period, 'Calender'[Date] )
VAR LastDateWithSales = EOMONTH(MAX ( FailureData_ICF_Trend[repairmonth] ),0)
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

 

 Thanks in advance

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@kuldeepjain Try this method: Better Rolling Average - Microsoft Power BI Community Just use SUMX instead of AVERAGEX



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg,  the issue is to get the comman range (overlapping dates) like sumif on two different coloum and then pass these dates for rolling sum

 

Or you can understand like and conditions in dateinperiod function.

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