Forum Discussion
Days Beetween deliverydates
Hi
i have a table with PO/Parts/deliverydate
| 29.06.2023 | |||
| 6238447 | 4715 | 29.06.2023 | 0 |
| 6240493 | 5050 | 16.06.2023 | |
| 6238006 | 5050 | 24.06.2023 | 8 |
| 552230 | 5053 | 01.06.2023 | |
| 552230 | 5053 | 15.06.2023 | 14 |
| 552230 | 5053 | 29.06.2023 | 14 |
| 6240497 | 78902 | 20.06.2023 | |
| 6240576 | 78902 | 20.06.2023 | 0 |
| 6240915 | 78902 | 27.06.2023 | 7 |
sorry i hope this table shows it. I want in Power Bi via Dax calculate the days beetween the deliverdates from each part
| PO | Part | Date LfD | days |
| 551196 | 4711 | 07.06.2023 | |
| 551197 | 4711 | 19.06.2023 | 12 |
| 82706078 | 4712 | 23.06.2023 | |
| 82693981 | 4712 | 30.06.2023 | 7 |
| 5555125 | 4713 | 07.06.2023 | |
| 5555126 | 4713 | 22.06.2023 | 15 |
| 6238279 | 4715 | 29.06.2023 | |
| 6238447 | 4715 | 29.06.2023 | 0 |
| 6240493 | 5050 | 16.06.2023 | |
| 6238006 | 5050 | 24.06.2023 | 8 |
| 552230 | 5053 | 01.06.2023 | |
| 552230 | 5053 | 15.06.2023 | 14 |
| 552230 | 5053 | 29.06.2023 | 14 |
| 6240497 | 78902 | 20.06.2023 | |
| 6240576 | 78902 | 20.06.2023 | 0 |
| 6240915 | 78902 | 27.06.2023 | 7 |
- Kishore_KVN3 years agoSolution Sage
You should have explained it better. Any ways here is the solution.
Use this measure to get days.
Duration = Var Start_Date = CALCULATE(MIN('Table'[Date LfD]),ALLEXCEPT('Table','Table'[Part])) Var End_Date = CALCULATE(MAX('Table'[Date LfD]),ALLEXCEPT('Table','Table'[Part])) Var Result = DATEDIFF(Start_Date,End_Date,DAY) Return ResultOutput looks like this:
If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!
- RWWRRW3 years agoRegular Visitor
Not quite yet. It now correctly displays the daydiffernz from the first to the last delivery date. But the days between several delivery dates unfortunately not.
See marked in green.
For Part 5053 I expected from June 1 to June 15 (first delivery date to next delivery date)14 days difference from June 14 to June 29 (next delivery date to next) the difference of 14 days.
In the next part I have three delivery dates, here I would have expected as result 0 and in the second the 7 days day difference.
There can also be several delivery dates per part
- danextian3 years agoSuper User
Hi RWWRRW
You can use RANKX to rank the dates by part and another calc column to get the previous date
DateRank = RANKX ( FILTER ( 'Table', 'Table'[Part] = EARLIER ( 'Table'[Part] ) ), 'Table'[Date LfD], , ASC, DENSE )PrevDate (RANKX) = CALCULATE ( MAX ( 'Table'[Date LfD] ), FILTER ( FILTER ( 'Table', 'Table'[Part] = EARLIER ( 'Table'[Part] ) ), 'Table'[DateRank] = EARLIER ( 'Table'[DateRank] ) - 1 ) )Or a single calc column to for the previous date
PrevDate (not RANKX) = CALCULATE ( MAX ( 'Table'[Date LfD] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Part] ), 'Table'[PrevDate (RANKX)] < EARLIER ( 'Table'[PrevDate (RANKX)] ) ) )For larger tables, I prefer the RANKX version. Performance shouldn't be an issue with small tables.
Now to get the difference, you can use either of the two previous date column
Difference = IF ( 'Table'[PrevDate (RANKX)] = BLANK (), 0, 'Table'[Date LfD] - 'Table'[PrevDate (RANKX)] )