Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi there. My sample data is as follows
DateTime | ID | TimeStamp | Value |
2023-11-01 13:00 | 1 | 2023-11-01 12:48 | 100 |
2023-11-01 13:00 | 1 | 2023-11-01 12:52 | 150 |
2023-11-01 13:00 | 2 | 2023-11-01 12:32 | 50 |
2023-11-01 13:00 | 2 | 2023-11-01 12:40 | 75 |
2023-11-01 14:00 | 1 | 2023-11-01 13:15 | 20 |
2023-11-01 14:00 | 1 | 2023-11-01 13:25 | 30 |
2023-11-01 14:00 | 2 | 2023-11-01 13:35 | 40 |
I am trying to retrieve the latest timestamp before each datetime for each ID and then summing them together.
Results table should look like this
DateTime | Sum |
2023-11-01 13:00 | 225 (150 + 75) |
2023-11-01 14:00 | 70 (30 + 40) |
I am using direct query mode
Can I have some help with some DAX that would achieve this?
Thanks
Hi,
Please check the below picture and the attached pbix file.
Expected result measure: =
VAR _datetime =
MAX ( Data[DateTime] )
VAR _t =
FILTER (
SUMMARIZE ( Data, Data[ID], Data[TimeStamp], Data[Value] ),
Data[TimeStamp] <= _datetime
)
VAR _resulttable =
INDEX ( 1, _t, ORDERBY ( Data[TimeStamp], DESC ),, PARTITIONBY ( Data[ID] ) )
RETURN
IF ( HASONEVALUE ( Data[DateTime] ), SUMX ( _resulttable, Data[Value] ) )
INDEX function (DAX) - DAX | Microsoft Learn
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
10 | |
6 |