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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Navaska
Frequent Visitor

Show last value in direct query

Hi there,

 

Am currently trying to configure a measure to only show the most current value for a temperature node. to put on a card.

 

I have the following measure to give me the most recent date for temp-3, 

 

Latest DateTime = MAXX(FILTER(ALL('temphum'),'temphum'[device_id]="temp-3"),temphum[received_at])
 
That works fine to get me the most recent date for temp-3, yet when I go to get a sum for the temperature with a filter on that date, the measure just gives me a "(Blank)" response. 
 
Any help would be appreciated,
 
Thanks.
 
Measure =
    CALCULATE (
        SUM ( 'temphum'[temperature] ),
        FILTER (
               ALLSELECTED('temphum'),
               'temphum'[device_id] = "temp-3"&&
               temphum[received_at] = [Latest DateTime]
        )      
    )
 
 
device_idreceived_attemperature
temp-42024-02-28T07:06:41.3582789    22.3
temp-52024-02-28T07:08:04.9087494    22.2
temp-32024-02-28T07:09:23.3961330    24.3
temp-42024-02-28T07:31:45.5189047    22.2
temp-52024-02-28T07:33:07.1889647    22
temp-32024-02-28T07:34:26.2270203    25.4
temp-12024-02-28T07:40:19.3694651    22.3
temp-22024-02-28T07:40:33.9704419    22.2
temp-52024-02-28T07:43:09.6143039    22
temp-32024-02-28T07:44:26.7001187    25.7
temp-42024-02-28T07:46:47.5482312    22.1
temp-32024-02-28T07:49:28.3065626    26
temp-22024-02-28T07:50:36.5310726    22.2

 

1 ACCEPTED SOLUTION

Hi there,

 

Have tried this, and yet it has not worked.

 

I have another idea with regards to the Top N function for displaying most current temperature. 

Navaska_1-1710934404347.png

 

 

I am able to display the most current temperature and humidity.

 

Thanks for the support.

 

Cheers

 

View solution in original post

9 REPLIES 9
some_bih
Super User
Super User

Hi @Navaska as I understand you need solution at received_at level (not calendar single date level), so it will be the best if you can share pbi file (link to office 365, dropbox, googledrive...) with example for expected output.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi there,

 

I have given the two links for the dashboard and the data, keep in mind that the data is pulled from an SQL table through Direct Query. If possible, set up an SQL table with that sample data and have power BI direct query to it. That will be the same situation I have. 

 

Another thought, could it be a timezone configuration error? My data is coming in through AEST (UTC +10), and power Bi is setup to read the data in UTC time? Let me know what you think.

 

Thanks.

PBI Dashboard https://www.dropbox.com/scl/fi/13v0b3ql2ohg8svff31ri/Dashboard.pbix?rlkey=x3tfc6w4padg3z4qu5jbfe5pe&...

 

Excel Data https://www.dropbox.com/scl/fi/07p4jtfme4srqtouzs975/test-data.xlsx?rlkey=bdnuyzj0jefxx6o4bz2hpqy3i&...

 

 

Hi @Navaska I will try at first with import mode 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi @Navaska try to create two measures as following (order of creation is important):

1. Max received_at = MAX(Sheet1[received_at])

2. 

Max_temp_at_max_rec =
VAR __device_id=SELECTEDVALUE(Sheet1[device_id])
var __max_received=MAX(Sheet1[received_at])
RETURN
CALCULATE(
sum((Sheet1[temperature])),
FILTER(Sheet1, Sheet1[device_id]=__device_id && Sheet1[received_at]=__max_received)
)
 
In simple matrix or one the card you should get output as below. 
some_bih_1-1710157612734.png

 


 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi there,

 

I have tried the method you provided, with creating the first measure first, and then creating the second measure second. 

 

I can see the max_received_at for each device, yet the Max_temp_at_max_rec is still blank. 

When I swap to import mode, the measures work and show the most current value. 

 

Questions:

  • Was the storage mode set to DirectQuery for when you tested those measures? As this is the key factor for having live data from the SQL database
  • Does the format of the date time matter e.g. yyyy-mm-ddThh:mm:ss.sssssss

 

Are there any other settings/data formats I need to configure in order to get this to work? Am struggling to see this working in the way I intended and am worried that it will not be possible.

 

Thanks.

Hi @Navaska 

Try v2 (not tested) with IF HASONEVALUE combination. 

I could not test DirectQuery before weekend

 

Max_temp_at_max_rec v2 =
VAR __device_id=IF ( HASONEVALUE( Sheet1[device_id] ), VALUES( Sheet1[device_id] ))
 
 
var __max_received=MAX(Sheet1[received_at])
RETURN
CALCULATE(
sum((Sheet1[temperature])),
FILTER(Sheet1, Sheet1[device_id]=__device_id && Sheet1[received_at]=__max_received)
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi there,

 

Have tried this, and yet it has not worked.

 

I have another idea with regards to the Top N function for displaying most current temperature. 

Navaska_1-1710934404347.png

 

 

I am able to display the most current temperature and humidity.

 

Thanks for the support.

 

Cheers

 

some_bih
Super User
Super User

Hi @Navaska DAX function best practice: ALLSELECTED should be only used in visual as it is "the most complex" function in DAX.

Without your model and details, it is hard to provide solid possible solution, or solution at all, still try v2

Measure v2 =
VAR __LatestDateTime = MAXX(FILTER(ALL('temphum'),'temphum'[device_id]="temp-3"),temphum[received_at])

RETURN
CALCULATE (
SUM ( 'temphum'[temperature] ),
FILTER (
ALLSELECTED('temphum'),
'temphum'[device_id] = "temp-3"&&
temphum[received_at] = __LatestDateTime
)
)

 

There are some limitations for DirectQury for this function-check link





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi there,

 

I have tried your measure V2 solution, yet still no result, the outcome is (Blank). Is there some advanced option you can enable to see the calculations working behind the measure? 

 

Is there any other data I can provide to assist you in helping me resolve this issue? 

 

I have also created a measure that will give an output of 1 or 0 if the most current date of the temp-3 device equals the most current date of the calendar created by the temp-3 device. Is there a way I can use this measure to filter the value shown?

 

Any help would be appreciated.

 

Calendar = GENERATESERIES(MIN(temphum[received_at]), MAX(temphum[received_at]), TIME(0, 1, 0))
 
Check =
VAR DateFilter = MAX('Calendar'[Value])
VAR CurrentDate = CALCULATE(
     MAX(temphum[received_at]),
     ALLEXCEPT(
        'temphum',
        'temphum'[device_id]
     ),
     temphum[received_at] <= DateFilter
)
RETURN IF(LASTNONBLANK(temphum[received_at], 1) = CurrentDate, 1, 0)

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.