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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DW868990
Helper IV
Helper IV

DAX for latest and previous value with varying date periods

Hi, 

 

I have a matrix like the one below and require 2 measures - 

Firstly a measure that returns the latest value for each product, so in the example below this would return 63 for Ball, but 64 for Pear, even though both those values come from different months. 

Secondly, a measure that returns the previous value for each product, so in the example below the previous value for Apple would be 85 and it would be 25 for Ball.

 

DW868990_0-1683869093778.png

 

Any advise appreciated, thank you.

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @DW868990 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create 2 measures.

Measure1 =
VAR _1 =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
        ),
        'Table'[month-year]
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
                && 'Table'[month-year] = _1
        )
    )
Measure2 =
VAR _1 =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
        ),
        'Table'[month-year]
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
                && 'Table'[month-year] < _1
        )
    )

vrongtiepmsft_0-1684119513237.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-rongtiep-msft
Community Support
Community Support

Hi @DW868990 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create 2 measures.

Measure1 =
VAR _1 =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
        ),
        'Table'[month-year]
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
                && 'Table'[month-year] = _1
        )
    )
Measure2 =
VAR _1 =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
        ),
        'Table'[month-year]
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[product] = SELECTEDVALUE ( 'Table'[product] )
                && 'Table'[month-year] < _1
        )
    )

vrongtiepmsft_0-1684119513237.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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