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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
annie_liu
Helper I
Helper I

Sum Difference between two date entries via matrix

Hello,

   I was trying to get the difference between the Grade Level between the latest week and the prior week within this matrix table.

so this one I want to see a measure that say Difference:  Take that latest $ subtract from the prior week pull date.

Sometimes the Pulled date is out of order so it would 10/16/2023 would be the 2nd column and  10/9/2023 would be the 3rd column, so the measure subtracts the latest data from the earlier data.

 

Rows ---->GL

Column -----> Pulled Date 

Values---->   Sum of Total: Budget 

 

Matrix differences.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @annie_liu ,

I updated my sample pbix file(see the attachment), please check if that is what you want. You can update the measure [Difference] as below to get it:

Difference = 
VAR _gl =
    SELECTEDVALUE ( 'Table'[GL] )
VAR _latestwk =
    CALCULATE ( MAX ( 'Table'[Pulled Date] ), ALLSELECTED ( 'Table' ) )
VAR _preweek =
    CALCULATE (
        MAX ( 'Table'[Pulled Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Pulled Date] < _latestwk )
    )
VAR _lwkbuddget =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && 'Table'[Pulled Date] = _latestwk
        ),
        [Sum of Budget]
    )
VAR _pwkbuddget =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && 'Table'[Pulled Date] = _preweek
        ),
        [Sum of Budget]
    )
RETURN
    IF ( ISBLANK ( _lwkbuddget ), 0, _lwkbuddget )
        - IF ( ISBLANK ( _pwkbuddget ), 0, _pwkbuddget )

vyiruanmsft_0-1699937785894.png

Best Regards

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @annie_liu ,

You can create two measures as below to get it, please find the details in the attachment.

Sum of Budget = SUM('Table'[Budget]) 
Difference =
VAR _gl =
    SELECTEDVALUE ( 'Table'[GL] )
VAR _latestwk =
    CALCULATE (
        MAX ( 'Table'[Pulled Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[GL] = _gl && [Sum of Budget] > 0 )
    )
VAR _preweek =
    CALCULATE (
        MAX ( 'Table'[Pulled Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && [Sum of Budget] > 0
                && 'Table'[Pulled Date] < _latestwk
        )
    )
VAR _lwkbuddget =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && 'Table'[Pulled Date] = _latestwk
        ),
        [Sum of Budget]
    )
VAR _pwkbuddget =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && 'Table'[Pulled Date] = _preweek
        ),
        [Sum of Budget]
    )
RETURN
    _lwkbuddget - _pwkbuddget

vyiruanmsft_0-1699606754029.png

Best Regards

This is good! It works except the difference for a decrease from 210 to  0 should be a negative number in differences..(210) since I am working with $$.  -- How would that be incorporated?

 

Matrix differences.png

 

 

 

Anonymous
Not applicable

Hi @annie_liu ,

I updated my sample pbix file(see the attachment), please check if that is what you want. You can update the measure [Difference] as below to get it:

Difference = 
VAR _gl =
    SELECTEDVALUE ( 'Table'[GL] )
VAR _latestwk =
    CALCULATE ( MAX ( 'Table'[Pulled Date] ), ALLSELECTED ( 'Table' ) )
VAR _preweek =
    CALCULATE (
        MAX ( 'Table'[Pulled Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Pulled Date] < _latestwk )
    )
VAR _lwkbuddget =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && 'Table'[Pulled Date] = _latestwk
        ),
        [Sum of Budget]
    )
VAR _pwkbuddget =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[GL] = _gl
                && 'Table'[Pulled Date] = _preweek
        ),
        [Sum of Budget]
    )
RETURN
    IF ( ISBLANK ( _lwkbuddget ), 0, _lwkbuddget )
        - IF ( ISBLANK ( _pwkbuddget ), 0, _pwkbuddget )

vyiruanmsft_0-1699937785894.png

Best Regards

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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