Power Pivot Dax measure previous item

dicken

Active Member
Joined
Feb 12, 2022
Messages
277
Office Version
  1. 365
Platform
  1. Windows
Hi, I have the following measure to return previous row item based on consecutive date, work ok,

Excel Formula:
PrevItem:=VAR maxd = MAX(Table1[Date]) 
RETURN LOOKUPVALUE(Table1[Item], Table1[Date],maxd-1)
But when it's dropped in a pivot table its first value is filtered out, I'd like to keep it.
I know I could use pivot table options show items with no data, but would like to incorporate this into t the measure;
Ive tried using and IF statement, so IF measure returns a result , true, use the measure else put in a blank, but even though this has worked in the past
in this case it caused an error.
1669727426628.png

Richard.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
LOOKUPVALUE already returns BLANK if nothing matches - that's why you're not seeing the item. If you don't want to use the pivot table options, you need to return something.
 
Upvote 0
I just needed to re-work things a bit and use a "" zero length txt string rather than the blank() ,
so
PrevItem :=
Excel Formula:
VAR oneItem =
    IF ( HASONEVALUE ( Table1[Date] ), VALUES ( Table1[Date] ) )
VAR less1 =
    MAXX ( FILTER ( ALL ( Table1[Date] ), Table1[Date] < oneItem ), Table1[Date] )
VAR lkup =
    LOOKUPVALUE ( Table1[Item], Table1[Date], less1 )
RETURN
    IF ( lkup = BLANK (), "", lkup )

Thanks for the pointers,
RD
 
Upvote 0
You should be able to use the final argument of LOOKUPVALUE:

LOOKUPVALUE ( Table1[Item], Table1[Date], less1, "" )
 
Upvote 0
Solution
You should be able to use the final argument of LOOKUPVALUE:

LOOKUPVALUE ( Table1[Item], Table1[Date], less1, "" )
Thanks, didn't realise there was an alternate result will try it.

rd
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top