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
Pandadev
Post Prodigy
Post Prodigy

Lookup based on matching history id and next date based on id

I have 2 tables that are matched by history_id

within both tables there is also id which is linked by both tables.

What I am trying to do is bring in the next history row where id is matched based on the date

of the event from the match of historyid.

Example

Table 1 has 

ID     HistoryID  Date

 

 

History Table

ID     HistoryID  Date

 

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @Pandadev  ,

Here are the steps you can follow:

1. Create measure.

Measure =
var _select = SELECTEDVALUE('Table'[DateTime])
var _1=CALCULATE(COUNT('Table'[Location]),FILTER(ALL('Table'),'Table'[ID]=MAX('Table'[ID])&&'Table'[Location]="Manchester"&&'Table'[DateTime]>=_select-28&&'Table'[DateTime]<=_select))
var _2=CALCULATE(COUNT('Table'[Location]),FILTER(ALL('Table'),'Table'[ID]=MAX('Table'[ID])&&'Table'[Location]="London"&&'Table'[DateTime]>=_select-28&&'Table'[DateTime]<=_select))
return
SWITCH(
    TRUE(),
    _1>_2,"Manchester",
    _1<_2,"London",
    BLANK())

2. Result:

v-yangliu-msft_0-1611120799568.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Pandadev , Try like ?

Rolling 30 day = CALCULATE(MAx(Table[Location]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-30,Day))

 

with help from dat table

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

I get an error saying a single value for Location in Table cannot be determined , this can happen when a column contains many values without specifying an aggregation such as min , max , count to get single result

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.