cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
VJ89
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

 

 

nameDateScoremeasure value
Alice01-02-2017788
Sam01-02-2017679
Sam01-03-2017896
Alice01-03-2017567

 

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.

 

Can anyone please help me with this scenario?

1 ACCEPTED SOLUTION

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.

View solution in original post

4 REPLIES 4
LaurentCouartou
Solution Supplier
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?

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.

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.

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

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors