Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I am trying to create a measure where the difference between a vehicle's today's Start Odometer Reading and Previous day's End Odometer reading. Now, the previous day can be 7th Jan or any other day when the vehicle was used.
I am using this variable to get the previous date and then using it in another variable's filter.
Solved! Go to Solution.
Hi,
You may download my PBI file from here.
Hope this helps.
Try the measure, below, I have take out the variable as measure to show the result.
Difference =
var todaystart = CALCULATE(MAX([Vehicle startOdo]),FILTER(ALL('Table'),[Date]=MAXX(ALL('Table'),[Date])))
var previousend= CALCULATE(MAX([Vehicle endOdo]),FILTER(ALL('Table'),[Date]=CALCULATE(MAX([Date]),FILTER(ALL('Table'),[Date]<CALCULATE(MAX([Date]),ALL('Table'))))))
Return todaystart-previousend
Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.
Hi,
Share a dataset and show the expected result.
You can access the dataset using this link.
What I want is:
28th Dec's Start Odo - 24th Dec's End Odo
24th Dec's Start Odo - 22nd Dec's End Odo
Today's Start Odo - Previous Reading Day's End Odo
I would add dates in matrix column, Vehicle in the rows and the value would contains the Difference Value.
Hi,
Why should it be 24th Dec's Start Odo - 22nd Dec's End Odo when there is data for 23rd Dec? Should it not be 24th Dec's Start Odo - 23rd Dec's End Odo? Also, for the same registration, ow can there there be 2 rows for the same Date? Please clarify.
Hi,
I missed 23rd Dec so yeah, 24th Dec StartOdo - 23rd Dec EndOdo.
The challange is 28th Dec StartOdo - 24th Dec EndOdo.
A vehicle can be driven twice in a day but it happens occasionally. So, you can just assume a single 23rd Dec.
Hi,
You may download my PBI file from here.
Hope this helps.
Hi,
It does seem like the correct solution but I can't download it. It gets downloaded as a bunch of files instead of a single pbix file.
Hi,
Please try again. It downloads just fine.
You are welcome.
@ziyabikram96 , you might want to try following measures,
Current Day = MAX ( 'Driver Daily Data(Whole)'[Date] )
Previous Day = PREVIOUSDAY( 'Driver Daily Data(Whole)'[Date] )
As to "Second Last Date", here's a more verbose way in line with your measure,
Second Last Date =
VAR __dd = [Current Day]
RETURN
MINX (
TOPN (
2,
CALCULATETABLE (
'Driver Daily Data(Whole)',
'Driver Daily Data(Whole)'[Date] <= __dd
),
'Driver Daily Data(Whole)'[Date]
),
'Driver Daily Data(Whole)'[Date]
)
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi,
Second Last Date doesn't work when dates are added in matrix column and vehicles in the rows. Date context renders it ineffective.
@ziyabikram96 - You will need to incorporate an ALL into your filter context so that you effectively override the filter from the slicer in your measure.
When I select 8th Jan from the filter or have in the matrix column, I want it to take the Start Odo of 8th Jan and End Odo of 7th Jan. Instead it takes the End Odo of 8th Jan.
I have also used that before but didn't work.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
99 | |
76 | |
64 | |
58 |
User | Count |
---|---|
148 | |
113 | |
97 | |
84 | |
67 |