Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hello Everyone,
I'm still getting a hang of Dax, and every now and then I run into issues I haven't been able to find online. I'm hoping for a little assistance. My goal is to create a rolling collision rate (per 100,000 KM). Of course, this was easy in excel, but the issue I'm having with Dax is that it's giving me random numbers before March 2021 (i.e. please see columns "R12MDistance"). The Dax I used for each column were:
R12MDistance =
Var _MaxDate = MAX('Date'[Date])
Var Result =
CALCULATE(
[TotalMonthlyDistance], 'Date'[Date] <= _MaxDate,
ALL('Date')
)
Return
Result
R12MDistance v2 =
VAR MaxDate = MAX('Date'[Date])
VAR MinDate = EDATE(MaxDate, -12)
VAR Result =
CALCULATE(
[TotalMonthlyDistance],
FILTER(ALL('Date'),
'Date'[Date] <= MaxDate &&
'Date'[Date] > MinDate)
)
RETURN
Result
R12MDistance v3 =
CALCULATE(
[Total Monthly Distance], DATESINPERIOD('Date'[Date], MAX('Date'[Date]),-12,MONTH)
)
Since there are no recorded KM before March 2021, what I want is for the first distance running total to be 567564 KM then start adding the months after.
Ultimately the formula would end up looking like this:
R12MCollisionRate =
Divide([R12MPreventable],[R12MDistance])*100000
Below is a snippet of the data I'm working with. Thank you for your time and assistance.
Year | Month | PreventableWithZero | R12MPreventable | TotalMonthlyDistance | R12MDistance | R12MDistance v2 | R12MDistance v3 |
2020 | April | 1 | 19 | 2527252 | |||
2020 | May | 2 | 19 | 2617511 | |||
2020 | June | 1 | 20 | 2707770 | |||
2020 | July | 4 | 24 | 2798029 | |||
2020 | August | 1 | 24 | 2888288 | |||
2020 | September | 0 | 24 | 2978547 | |||
2020 | October | 1 | 22 | 3068806 | |||
2020 | November | 0 | 19 | 3159065 | |||
2020 | December | 1 | 17 | 3249324 | |||
2021 | January | 0 | 15 | 3339583 | |||
2021 | February | 2 | 13 | 3429842 | |||
2021 | March | 1 | 14 | 567564 | 25655097 | 12486408 | 6810768 |
2021 | April | 0 | 13 | 515028 | 46914040 | 23817024 | 12991104 |
2021 | May | 0 | 11 | 481293 | 67819904 | 34405470 | 18766620 |
2021 | June | 0 | 10 | 516411 | 91163310 | 47846808 | 24963552 |
2021 | July | 0 | 6 | 459690 | 113100535 | 55879692 | 30479832 |
2021 | August | 0 | 5 | 445834 | 135347476 | 65688040 | 35829840 |
2021 | September | 0 | 5 | 469338 | 159543765 | 76013476 | 41461896 |
2021 | October | 0 | 4 | 436720 | 183178302 | 85621316 | 46702536 |
2021 | November | 0 | 4 | 481630 | 209797049 | 100590684 | 52482096 |
2021 | December | 0 | 3 | 433599 | 235073568 | 105756354 | 57685284 |
2022 | January | 1 | 4 | 404657 | 259799127 | 114658808 | 62541168 |
2022 | February | 4 | 6 | 398315 | 285016900 | 129031817 | 67320948 |
2022 | March | 0 | 5 | 510614 | 316758552 | 134655246 | 66637548 |
User | Count |
---|---|
15 | |
9 | |
8 | |
6 | |
5 |
User | Count |
---|---|
29 | |
18 | |
15 | |
7 | |
6 |