Power Pivot Dax measure previous item

dicken

Board Regular
Joined
Feb 12, 2022
Messages
213
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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,141
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
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

dicken

Board Regular
Joined
Feb 12, 2022
Messages
213
Office Version
  1. 365
Platform
  1. Windows
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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,141
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
You should be able to use the final argument of LOOKUPVALUE:

LOOKUPVALUE ( Table1[Item], Table1[Date], less1, "" )
 
Upvote 0
Solution

dicken

Board Regular
Joined
Feb 12, 2022
Messages
213
Office Version
  1. 365
Platform
  1. Windows
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,187,001
Messages
5,961,057
Members
438,516
Latest member
Fintrics

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
Top