Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Get latest value measure doesn't work in DirectQuery mode

Hello,

 

I'm trying to convert the power BI report data resource from Import to DirectQuery (Azure SQL). This measure is used to get the latest value for each category.

 

 

Measure =
VAR LatestTime = CALCULATE(MAX(Table[Time]), FILTER(Table, Table[Category] =1))
RETURN CALCULATE(AVERAGE(Table[Value]), FILTER(Table, [Category] = 1), FILTER(Table, [Time] = LatestTime))

 

 
It works fine in Import mode but returns nothing in DirectQuery mode. Also, it works if I use TODAY() instead of the calculated LatestTime in the RETURN line in DirectQuery mode, which means two filters work with the CALCULATE method, but an extra calculation fails?
 
There is no error or warning message displayed. I'm using Microsoft Power BI Desktop Version 2.82.5858.961 64-bit (June 2020).
 
Could someone please let me know which part causes the issue?
 
Thanks
1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

You may try the following measure to see if it helps.

Measure =
VAR LatestTime =
    CALCULATE ( 
         MAX ( 'Table'[Time] ), 
         FILTER ( 
             ALLSELECTED('Table'), 
             'Table'[Category] = 1 
         ) 
    )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[Value] ),
        FILTER ( 
               ALLSELECTED('Table'),
               'Table'[Category] = 1&&
               'Table'[Time]=LatestTime
        )       
    )

 

About limitation and considerations in Direct Query mode, please refer to the document .

 

Best Regards

Allan

 

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

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

You may try the following measure to see if it helps.

Measure =
VAR LatestTime =
    CALCULATE ( 
         MAX ( 'Table'[Time] ), 
         FILTER ( 
             ALLSELECTED('Table'), 
             'Table'[Category] = 1 
         ) 
    )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[Value] ),
        FILTER ( 
               ALLSELECTED('Table'),
               'Table'[Category] = 1&&
               'Table'[Time]=LatestTime
        )       
    )

 

About limitation and considerations in Direct Query mode, please refer to the document .

 

Best Regards

Allan

 

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

 

 

lbendlin
Super User
Super User

VAR LatestTime = CALCULATE(MAX(Table[Time]),All(Table), Table[Category] =1)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors