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

LOOKUPVALUE takes a very long time

Hi All, 


I have this data set that is updated daily:

Yaa_D_0-1638351806111.png

In order to calculate a daily diff of [total] for each id I've added the following columns:

total_yesterday = LOOKUPVALUE(
[total],
[file_date],[file_date]-1,
[Id],[Id],
[total])
daily_diff = [total] - [total_yesterday]

to create this:

Yaa_D_1-1638353005231.png


My problem is, with ~10000 unique ids and ~30 days of data, the [total_yesterday] column takes about 10-12 minuts to be calculated.

Is this the correct way to find the daily total? or is there a better, more efficiant way to make this calculation? 

 

Thanks for the help!

 

2 ACCEPTED SOLUTIONS
v-stephen-msft
Community Support
Community Support

Hi @Yaa_D ,

 

Try this

total_yesterday = var _yeasterday=CALCULATE([total],PREVIOUSDAY('Table'[file_date]))
return IF(ISBLANK(_yeasterday),[total],+_yeasterday)
daily_diff = [total]-[total_yesterday]

vstephenmsft_0-1638869864326.png

 

 

Best Regards,

Stephen Tao

 

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

View solution in original post

smpa01
Super User
Super User

@Yaa_D  my take on this is to use a measure like this. In case, you have gaps in date

Measure =
VAR _currentTotal =
    SUM ( 'Table'[total value] )
VAR _visibleDate =
    MAX ( 'Table'[file_date] )
VAR _visibleId =
    MAX ( 'Table'[id] )
VAR _immediatelyPreceding =
    CALCULATE ( MAX ( 'Table'[file_date] ), 'Table'[file_date] < _visibleDate )
VAR _immediatelyPrecedingTotal =
    CALCULATE (
        SUM ( 'Table'[total value] ),
        'Table'[id] = _visibleId
            && 'Table'[file_date] = _immediatelyPreceding,
        REMOVEFILTERS ( 'Table' )
    )
RETURN
    _currentTotal - _immediatelyPrecedingTotal

 

smpa01_0-1638896043587.png

 

 

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

3 REPLIES 3
smpa01
Super User
Super User

@Yaa_D  my take on this is to use a measure like this. In case, you have gaps in date

Measure =
VAR _currentTotal =
    SUM ( 'Table'[total value] )
VAR _visibleDate =
    MAX ( 'Table'[file_date] )
VAR _visibleId =
    MAX ( 'Table'[id] )
VAR _immediatelyPreceding =
    CALCULATE ( MAX ( 'Table'[file_date] ), 'Table'[file_date] < _visibleDate )
VAR _immediatelyPrecedingTotal =
    CALCULATE (
        SUM ( 'Table'[total value] ),
        'Table'[id] = _visibleId
            && 'Table'[file_date] = _immediatelyPreceding,
        REMOVEFILTERS ( 'Table' )
    )
RETURN
    _currentTotal - _immediatelyPrecedingTotal

 

smpa01_0-1638896043587.png

 

 

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
v-stephen-msft
Community Support
Community Support

Hi @Yaa_D ,

 

Try this

total_yesterday = var _yeasterday=CALCULATE([total],PREVIOUSDAY('Table'[file_date]))
return IF(ISBLANK(_yeasterday),[total],+_yeasterday)
daily_diff = [total]-[total_yesterday]

vstephenmsft_0-1638869864326.png

 

 

Best Regards,

Stephen Tao

 

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

@Yaa_D , Try like, if this can help

total_yesterday = Maxx(filter(Table, [file_date] = earlier([file_date]) && [Id] =earlier([Id])), [total])

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