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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Tommy_K78
Frequent Visitor

Need help with DAX to return the previous date's result

Dear community, 

 

I’m having trouble aligning the previous data with the current data on a specific date in a matrix table.

 

I have a matrix table displaying the Total for specific dates each month, and I want to add a second row to show the Total Prior, similar to the example below. 

Screenshot 2024-11-15 115208.png

 

 

Application Date and Settlement Date are on two different date dimension.

 

The issue I’m facing is that the Total Prior is appearing on the next day, even though there are no Total sales.

Screenshot 2024-11-15 120310.png

Total Prior = CALCULATE ( [Total], PREVIOUSDAY( ( dim_settlement_date[settlement_dt] ) ))
 
Thanks for your help.

 

1 ACCEPTED SOLUTION

Hi,

Thank you for your message, and I thought only two dim tables were there, and I just add the condition in the measure REMOVEFILTERS()

If there are more dimension tables, I need to specify which dimension tables to apply REMOVEFILTERS() function in the measure.

Please check the below fixed-measure and the attached pbix file whether it suits your requirement.

 

LastNonBlank amount: = 
VAR _t =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE (
                Data,
                DimApplicationDate[Year-Month],
                DimApplicationDate[Year-Month sort],
                DimSettlementDate[Date]
            ),
            REMOVEFILTERS (DimApplicationDate), REMOVEFILTERS(DimSettlementDate)
        ),
        "@total", [Total:]
    )
VAR _rownumber =
    ADDCOLUMNS (
        _t,
        "@rownumber",
            ROWNUMBER (
                _t,
                ORDERBY (
                    DimApplicationDate[Year-Month sort], ASC,
                    DimSettlementDate[Date], ASC
                )
            )
    )
VAR _currentrownumber =
    MAXX (
        FILTER (
            _rownumber,
            DimApplicationDate[Year-Month sort]
                = MAX ( DimApplicationDate[Year-Month sort] )
                && DimSettlementDate[Date] = MAX ( DimSettlementDate[Date] )
        ),
        [@rownumber]
    )
VAR _prevrownumber = _currentrownumber - 1
RETURN
    MAXX ( FILTER ( _rownumber, [@rownumber] = _prevrownumber ), [@total] )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1731643545058.png

 

 

Jihwan_Kim_0-1731643454173.png

 

ROWNUMBER function (DAX) - DAX | Microsoft Learn

 

LastNonBlank amount: =
VAR _t =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE (
                Data,
                DimApplicationDate[Year-Month],
                DimApplicationDate[Year-Month sort],
                DimSettlementDate[Date]
            ),
            REMOVEFILTERS ()
        ),
        "@total", [Total:]
    )
VAR _rownumber =
    ADDCOLUMNS (
        _t,
        "@rownumber",
            ROWNUMBER (
                _t,
                ORDERBY (
                    DimApplicationDate[Year-Month sort], ASC,
                    DimSettlementDate[Date], ASC
                )
            )
    )
VAR _currentrownumber =
    MAXX (
        FILTER (
            _rownumber,
            DimApplicationDate[Year-Month sort]
                = MAX ( DimApplicationDate[Year-Month sort] )
                && DimSettlementDate[Date] = MAX ( DimSettlementDate[Date] )
        ),
        [@rownumber]
    )
VAR _prevrownumber = _currentrownumber - 1
RETURN
    MAXX ( FILTER ( _rownumber, [@rownumber] = _prevrownumber ), [@total] )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

This is amazing and thank you so much. However, when I add slicers, part of the results appears to change.

 

Tommy_K78_0-1731657952168.png

 

This is the pbix file I'm using Tommy_K78_pbix

Hi,

Thank you for your message, and I thought only two dim tables were there, and I just add the condition in the measure REMOVEFILTERS()

If there are more dimension tables, I need to specify which dimension tables to apply REMOVEFILTERS() function in the measure.

Please check the below fixed-measure and the attached pbix file whether it suits your requirement.

 

LastNonBlank amount: = 
VAR _t =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE (
                Data,
                DimApplicationDate[Year-Month],
                DimApplicationDate[Year-Month sort],
                DimSettlementDate[Date]
            ),
            REMOVEFILTERS (DimApplicationDate), REMOVEFILTERS(DimSettlementDate)
        ),
        "@total", [Total:]
    )
VAR _rownumber =
    ADDCOLUMNS (
        _t,
        "@rownumber",
            ROWNUMBER (
                _t,
                ORDERBY (
                    DimApplicationDate[Year-Month sort], ASC,
                    DimSettlementDate[Date], ASC
                )
            )
    )
VAR _currentrownumber =
    MAXX (
        FILTER (
            _rownumber,
            DimApplicationDate[Year-Month sort]
                = MAX ( DimApplicationDate[Year-Month sort] )
                && DimSettlementDate[Date] = MAX ( DimSettlementDate[Date] )
        ),
        [@rownumber]
    )
VAR _prevrownumber = _currentrownumber - 1
RETURN
    MAXX ( FILTER ( _rownumber, [@rownumber] = _prevrownumber ), [@total] )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks, this worked like a charm!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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