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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
smpa01
Super User
Super User

DAX measure to show max of immediately preceding period's value in current period

Hello experts,

My source data is following

namedatevalperiod
a1/1/20201001
a1/1/20202001
a1/2/20203002
a1/2/20204002
a1/3/20205003
a1/3/20206003
b1/1/20207001
b1/1/20208001
b1/2/20209002
b1/2/202010002
b1/3/202011003
b1/3/202012003

 

On a matrix viz I want to show the max of current period's value and what was the max of immediately preceeding period's value. My desired output is following

namedate_maxVal_lastVal
a1/1/20202000
a1/2/2020400200
a1/3/2020600400
b1/1/20208000
b1/2/20201000800
b1/3/202012001000

 

I can't seem to figure out how to come to this. I have tried the following measure

 

Measure 3 = 
VAR _1 = MAX('Table'[period])-1
VAR _2 = CALCULATE(MAXX(FILTER('Table','Table'[period]=_1),'Table'[val]))
RETURN _2

 

but I can't seem to figure out where it is going wrong

Capture.PNG

If you can please would be great.

Thank you in advance.

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
smpa01
Super User
Super User

Sorry figured out by myself..

Measure 3 = 
VAR _1 = MAX('Table'[period])-1
VAR _2 = CALCULATE(MAXX(FILTER('Table','Table'[period]=_1),'Table'[val]),ALLEXCEPT('Table','Table'[name]))
RETURN _2

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @smpa01 

 

Please try the below measure.

 

Max Val preceeding period =
VAR currentperiod =
MAX ( Data[period] )
RETURN
CALCULATE (
MAX ( Data[val] ),
FILTER ( ALLEXCEPT ( Data, Data[name] ), Data[period] = currentperiod - 1 )
)

 

Hi, My name is Jihwan Kim.

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

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.


Go to My LinkedIn Page


smpa01
Super User
Super User

Sorry figured out by myself..

Measure 3 = 
VAR _1 = MAX('Table'[period])-1
VAR _2 = CALCULATE(MAXX(FILTER('Table','Table'[period]=_1),'Table'[val]),ALLEXCEPT('Table','Table'[name]))
RETURN _2

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.