The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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.
User | Count |
---|---|
28 | |
12 | |
8 | |
7 | |
5 |
User | Count |
---|---|
36 | |
14 | |
12 | |
7 | |
7 |