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! Request now

Reply
likvors_husband
Frequent Visitor

DAX Calculated Column for Comparing Values on Non-Consecutive Dates In the matching context

Hi everyone,

I'm working on a DAX calculation in Power BI where I need to compare a value on a given date with the value on the previous date for the same context of Product, Partner, Projection, and Element. However, the dates are not always consecutive and have duplicates*, so I'm using an Index column based on the date to help with this comparison.

In my example table, I'm encountering an issue where the rows with Index 13 and Index 32 are not recognized as the previous value.

edit*

 

PreviousValue =
VAR PreviousValue = 
    CALCULATE(
        SUM(FactData[Value]),
        TOPN(
            1,
            FILTER(
                ALLSELECTED('FactData'),
                'FactData[Product] = EARLIER('FactData'[Product]) &&
                'FactData'[Partner] = EARLIER('FactData'[Partner]) &&
                'FactData'[Element] = EARLIER('FactData'[Element]) &&
                'FactData'[Projection] = EARLIER('FactData'[Projection]) &&
                'FactData'[Index] < EARLIER('FactData'[Index])
            ),
            'FactData'[Index],
            DESC
        )
    )
RETURN
PreviousValue

 

 

Many thanks in advance for your help!

Index     Date     Product     Partner     Element     Value     Projection     PreviousValue     
108-Jan-24Product1Partner1Element17201-Apr-24 
215-Jan-24Product1Partner1Element17201-Apr-2472
322-Jan-24Product1Partner1Element17201-Apr-2472
429-Jan-24Product1Partner1Element17201-Apr-2472
505-Feb-24Product1Partner1Element15001-Apr-2472
612-Feb-24Product1Partner1Element15001-Apr-2450
719-Feb-24Product1Partner1Element15001-Apr-2450
826-Feb-24Product1Partner1Element15001-Apr-2450
904-Mar-24Product1Partner1Element15001-Apr-2450
1011-Mar-24Product1Partner1Element15001-Apr-2450
1118-Mar-24Product1Partner1Element15001-Apr-2450
1225-Mar-24Product1Partner1Element15001-Apr-2450
1302-Apr-24Product1Partner1Element14801-Apr-2450
1913-May-24Product1Partner1Element19601-May-24 
2020-May-24Product1Partner1Element19601-May-2496
3229-Jul-24Product1Partner1Element19601-Aug-24 
3331-Jul-24Product1Partner1Element19601-Aug-2496
3401-Aug-24Product1Partner1Element19601-Aug-2496
3505-Aug-24Product1Partner1Element19601-Aug-2496
3613-Aug-24Product1Partner1Element19601-Aug-2496
3719-Aug-24Product1Partner1Element19601-Aug-2496
1 ACCEPTED SOLUTION
likvors_husband
Frequent Visitor

Thank you, everyone, for your input! I wanted to share that I found the solution I was looking for right here on the forum. The method to compare values across non-consecutive rows was simpler than I thought and was already discussed in this thread. I hope this helps someone in the future as it did for me. Cheers!

View solution in original post

3 REPLIES 3
likvors_husband
Frequent Visitor

Thank you, everyone, for your input! I wanted to share that I found the solution I was looking for right here on the forum. The method to compare values across non-consecutive rows was simpler than I thought and was already discussed in this thread. I hope this helps someone in the future as it did for me. Cheers!

DataNinja777
Super User
Super User

Since the date column doesn't seem to contain duplicates, it appears that we may not need to use the index column.

The resulting output is shown below. 

DataNinja777_1-1724422067100.png

Please let me know if this meets your expectations.

I have attached an example PBIX file for your reference.

 

 

Thank you, DataNinja777! However, the date column does contain duplicates, which is why I included the index column. Apologies for not mentioning that earlier—I completely overlooked it.

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
Users online (1,976)