cancel
Showing results for
Did you mean:
Regular Visitor

## DAX previous month value

Hi All,

I have a scenario where i am supposed to get the previous month measure of the top scorer in the current month.

For example. my data look like below

 name Date Score measure value Alice 01-02-2017 78 8 Sam 01-02-2017 67 9 Sam 01-03-2017 89 6 Alice 01-03-2017 56 7

Current month highest scorer is SAM and its measure value is 6.

So right now i am looking for SAM's previous month measure value which is 9.

1 ACCEPTED SOLUTION
Solution Supplier

My suggestion:

```Previous month score for top scorer = 	VAR TopScorers = TOPN( 1, VALUES( Scores[name] ), CALCULATE(AVERAGE(Scores[Score])) )
VAR PrevMonth = CALCULATETABLE( DATEADD(Scores[Date],-1, MONTH), LASTDATE( Scores[Date]) )
RETURN
CALCULATE( AVERAGE(Scores[Score])
, TopScorers
, PrevMonth
)```

Note the TOPN function wil return several players if you have ties in your current selection. Hence the average calculation.

Also, in case several months/dates are selected, I take the last one and calculate the previous month for this date.

4 REPLIES 4
Solution Supplier

Say you are looking at the data for march and have a filter on name = "Alice", should the measure still return Sam's score for february?

Regular Visitor

If there is a filter ="Alice" then it should return the measure value of "Alice" for the month of Feb.

If no filter is present then it should give the Highest scorer's previous month value, in this case it will be "Sam's" Feb value.

Solution Supplier

My suggestion:

```Previous month score for top scorer = 	VAR TopScorers = TOPN( 1, VALUES( Scores[name] ), CALCULATE(AVERAGE(Scores[Score])) )
VAR PrevMonth = CALCULATETABLE( DATEADD(Scores[Date],-1, MONTH), LASTDATE( Scores[Date]) )
RETURN
CALCULATE( AVERAGE(Scores[Score])
, TopScorers
, PrevMonth
)```

Note the TOPN function wil return several players if you have ties in your current selection. Hence the average calculation.

Also, in case several months/dates are selected, I take the last one and calculate the previous month for this date.

Regular Visitor

Hey Thanks a lots, it worked like charm!! 🙂

Announcements

#### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

#### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

#### Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

#### Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors