Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello,
How can I get a differene from the last value? In this example I need the difference in mileage from the last entry.
(24,695 - 18,923)
(30,781 - 24,695) etc
Example)
Should be based on Equimpent Key and Date.
Thank you!
Hi @amandabus21
please try
=
SUMX (
SUMMARIZE (
'Table',
'Table'[EquipmentKey],
'Table'[CompletionDate],
'Table'[Mileage]
),
VAR CurrentMileage = 'Table'[Mileage]
VAR CurrentDate = 'Table'[CompletionDate]
VAR CurrentEquipmentTable =
CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[EquipmentKey] ) )
VAR TableBefore =
FILTER ( CurrentEquipmentTable, 'Table'[CompletionDate] < CurrentDate )
VAR PreviousRecord =
TOPN ( 1, TableBefore, 'Table'[CompletionDate] )
VAR PreviousMileage =
MAXX ( PreviousRecord, 'Table'[Mileage] )
RETURN
IF ( NOT ISEMPTY ( PreviousRecord ), CurrentMileage - PreviousRecord )
)
Oh! So sorry! I've wrongly copied the very last variable! Please use
@tamerj1 thank you!!! its still a bit off though.
Where the first one should be 0 because that is the frist entry, the second one should be 5,772 (24,695- 18,923).
third should be 6,086 (30,781-24,695) etc
Still not fixed. It is clear that the date values are still aligned left indicating that this is a text. Use the query editor (power query) to define the correct data of the column. However the first value will most probably remain wrong due to a gap in the code, other than that, other values shall be correct.
however we may also add additional dax to force correct order of the column
@tamerj1 That isnt the date i was using, but I changed it anyways. Still getting the same wrong values.
It wont let me attach a PBIX file
Ok got it:
I'm not sure where I would create a link from.
Maybe this may make more sense, this is the orginal Variable equation from Business Objects:
(Equipment key is Equipmemt.Equipment Level 01.Key)
=(If Previous([Equipment - Key]) <> [Equipment - Key] Then 0 Else [Mileage] - Previous([Mileage]))
@tamerj1 thank you so much for all your help! Just have one more question, do you know if I can put a rule or condition for that DAX statement to run only if the Equipment does not equal the previous? Otherwise it should default to 0
Fix the date data type. It should be DateTime data type not text data type.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |