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
Benito_BI
Frequent Visitor

DAX measure: get next value on current row

Hello,

 

I would like to get the categoryid of the next value based on the "End"date and "start"date.

See below the result category is the output that i need:

 

idgroupidcategoryidProductstartendqtyResult categoryid
12A1test1-1-20191-2-201912
13A2test21-2-20192-5-201914
14A2test21-3-20192-5-201914
4B1test181-5-2019 1 
5C4test32-5-2019 2 

 

i have used the following measure:

 

result_category =

VAR groups = SELECTEDVALUE(table[Groupid])
VAR enddate = SELECTEDVALUE(table[End])
VAR startdate = SELECTEDVALUE(table[Start])
VAR idInitial = SELECTEDVALUE(table[Id])
 
VAR new_date = CALCULATE(MINX(table,table[Start]),ALLSELECTED(table),table[Start]>=enddate,table[groupid]=groups)
VAR new_id = CALCULATE(MINX(table,table[Id]),ALLSELECTED(table),table[start]=new_date,table[groupid]=groups)
RETURN
CALCULATE(SELECTEDVALUE(table[categoryid]
),ALLSELECTED(table),table[id]=new_id

But this isnt working for me.
Could somebody point me in the right direction?
 
Kind regards,
3 REPLIES 3
Benito_BI
Frequent Visitor

I have found a way, but it only works on a small dataset. When i try it on a large dataset i get a memory error.

Does somebody have a idea how i can decrease the load so i wouldnt get a memory error?

result_categoryid = 
VAR v_end = SELECTEDVALUE(Table[end])
VAR v_group = SELECTEDVALUE(Table[groupid])
VAR v_nextstart = CALCULATE(MINX(Table,Table[start]),ALLSELECTED(Table),DATESBETWEEN(Table[start],v_end,EDATE(v_end,1)),Table[groupid]=v_group)
VAR v_id = CALCULATE(MINX(Table,Table[id]),ALLSESLECTED(Table),Table[start]=v_nextstart,Table[groupid]=v_group)
VAR v_category = CALCULATE(SELECTEDVALUE(Table[categoryid]),ALLSELECTED(Table),Table[id]=v_id)
RETURN
IF(SELECTEDVALUE(Table[end])=BLANK(),BLANK(),IF(SELECTEDVALUE(Table[id])=v_id,BLANK(),v_category))

 

Kind regards

Anonymous
Not applicable

Hi,

 

Have you tried using Lookupvalue. Basically you will need to Create a new column with the below DAX 

 

LOOKUPVALUE(Table[Category_ID],Table[End_Date],Table[Start_Date])

Hi,

 

I dont want to use a calculated column, i would like to use it in a measure.

 

And the lookupvalue also isnt working, this because the startdate of the next value could be later/higher then the rows enddate.

 

Kind regards,

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.

Top Solution Authors