Forum Discussion
Cumulative date comparison with if statements using variables
Dear experts,
I have some experience with Power BI/DAX but this challenge has proven beyond my skillset.
Requirements:
I am looking to calculate (I would presume via measure), the cumulative days late to the target date an item has accrued by the end of each month until it has been shipped. This is a cumulative measure, so it is measured more than once – the trigger is the end of the month itself.
These are the potential scenarios for a formula at the end of each month:
Once the days late per order has been calculated (Output I), I need to produce 3 more outputs based on the same logic:
- Output II – Total of order qty late reported at the end of each month. Table per order and sum for each month.
- Output III – Total Oder qty late times the number of days late (Output I x Output II). Table per order and sum for each month.
- Output IV – Average days late (Output III / Output II). Table per average of each month.
There is additional information for each order that I would like to use to aggregate and analyze these results. Which I assume can be done with normal PowerBI features.
Where I am so far:
After reading some blogs and watching some videos I have been able to create the first Output at the Order level entering the following information in a Matrix visualization but, as you may know, I cannot do anything with the data.
In the matrix visualization I am using as columns a Dates table that I generated via ‘Dates = CALENDARAUTO()’. In the rows I am entering a unique identifier for each order. And for the values I have created a Measure called ‘Order_Days_late’ where I have attempted to replicate the logic I explained in the first diagrams.
Here is the code for that measure. KEY: cdd_target_date = Target Date, OTD_Date = Actual Date
Order_days_late =
var adl =
calculate(
if(
max('SO and NDD List'[cdd_target_date]) < endofmonth(Dates[Date]) &&
max('SO and NDD List'[OTD_Date]) > endofmonth(previousmonth(Dates[Date])) &&
max('SO and NDD List'[OTD_Date]) < endofmonth(Dates[Date])
, (max('SO and NDD List'[OTD_Date])-max('SO and NDD List'[cdd_target_date])),
if(
max('SO and NDD List'[cdd_target_date]) < endofmonth(Dates[Date]) &&
(max('SO and NDD List'[OTD_Date]) = blank() || max('SO and NDD List'[OTD_Date]) > endofmonth(Dates[Date]))
,(ENDOFMONTH(Dates[Date])-max('SO and NDD List'[cdd_target_date]))
,blank()
)
)
, 'SO and NDD List'[OTD] = "N")
return
format(adl,0.00)
Any help would be strongly appreciated.
Thank you in advance for sharing the knowledge,
9 Replies
- littlemojopuppy
Community Champion
Hola! Can you provide some sample data to play with?
- AnonymousNot applicable
Here you go. Thanks!
Order ID Qty Target Date Actual Date F272 1 01-Oct-20 P775 1 01-Oct-20 J598 1 01-Oct-20 16-Nov-20 K954 1 01-Oct-20 U338 1 01-Oct-20 D543 3 01-Oct-20 N242 3 01-Oct-20 16-Nov-20 V501 1 01-Oct-20 R574 1 02-Oct-20 V236 1 02-Oct-20 G427 1 03-Oct-20 10-Oct-20 Y504 1 03-Oct-20 10-Oct-20 R207 1 03-Oct-20 02-Oct-20 L210 1 03-Oct-20 27-Nov-20 B380 1 04-Oct-20 Y816 1 04-Oct-20 X937 1 07-Oct-20 K773 1 07-Oct-20 S429 1 07-Oct-20 23-Oct-20 Z572 1 07-Oct-20 P171 1 07-Oct-20 A405 1 23-Oct-20 S280 1 23-Oct-20 29-Sep-20 X417 1 24-Oct-20 08-Oct-20 V452 1 24-Oct-20 05-May-20 X965 1 24-Oct-20 20-Jun-16 A380 1 24-Oct-20 19-Oct-20 C296 1 24-Oct-20 16-Oct-20 F963 1 24-Oct-20 16-Oct-20 C785 1 24-Oct-20 29-Oct-20 F757 1 24-Oct-20 29-Oct-20 P733 1 24-Oct-20 16-Oct-20 D234 1 24-Oct-20 16-Oct-20 D494 1 24-Oct-20 23-Oct-20 X101 1 24-Oct-20 16-Oct-20 X234 1 24-Oct-20 23-Oct-20 Z570 1 25-Oct-20 25-Sep-20 S556 2 25-Oct-20 22-Oct-20 D353 2 25-Oct-20 26-Oct-20 E653 2 25-Oct-20 26-Oct-20 R579 2 25-Oct-20 08-Oct-20 R477 4 25-Oct-20 16-Oct-20 U203 5 25-Oct-20 P617 1 30-Oct-20 M376 1 30-Oct-20 27-Aug-20 S183 1 30-Oct-20 27-Aug-20 W158 1 30-Oct-20 05-Nov-20 K613 1 30-Oct-20 N647 1 30-Oct-20 O125 1 30-Oct-20 K996 1 30-Oct-20 J357 1 30-Oct-20 05-Nov-20 O550 1 30-Oct-20 05-Nov-20 V826 1 30-Oct-20 05-Nov-20 N871 1 30-Oct-20 E879 3 30-Oct-20 U715 1 31-Oct-20 14-Nov-20 Y979 1 31-Oct-20 14-Nov-20 M959 1 31-Oct-20 T426 1 31-Oct-20 27-Oct-20 P801 1 31-Oct-20 27-Oct-20 S333 1 31-Oct-20 K921 1 31-Oct-20 R657 2 31-Oct-20 Z457 2 31-Oct-20 27-Oct-20 G870 8 31-Oct-20 27-Oct-20 T25L 1 31-Oct-20 B374 1 07-Nov-20 E911 1 07-Nov-20 L250 1 07-Nov-20 D434 1 07-Nov-20 11-Nov-20 Y522 1 07-Nov-20 11-Nov-20 F649 1 07-Nov-20 28-Oct-20 L495 1 07-Nov-20 21-Oct-20 Q345 1 07-Nov-20 Y179 1 13-Nov-20 B509 1 13-Nov-20 H741 1 13-Nov-20 J446 1 14-Nov-20 18-Oct-20 Z144 1 19-Nov-20 13-Nov-20 B721 1 19-Nov-20 13-Nov-20 I986 1 19-Nov-20 E428 1 19-Nov-20 13-Nov-20 M829 1 20-Nov-20 O345 1 23-Nov-20 Z697 1 23-Nov-20 15-Oct-20 R529 1 23-Nov-20 01-Oct-20 M349 1 23-Nov-20 01-Oct-20 B838 1 23-Nov-20 01-Oct-20 A536 1 23-Nov-20 G491 11 24-Nov-20 A515 12 24-Nov-20 23-Nov-20 T102 1 25-Nov-20 P322 1 25-Nov-20 26-Oct-20 M138 1 25-Nov-20 Y817 1 30-Nov-20 L859 1 30-Nov-20 27-Nov-20 Q380 1 30-Nov-20 W615 1 30-Nov-20 27-Nov-20 Y402 1 30-Nov-20 I873 6 30-Nov-20 S807 7 30-Nov-20 16-Nov-20 K225 5 30-Nov-20 23-Nov-20 S358 1 30-Nov-20 I639 1 05-Dec-20 29-Oct-20 G757 1 06-Dec-20 Y978 1 07-Dec-20 31-Aug-20 C689 1 07-Dec-20 J778 1 07-Dec-20 Z758 1 07-Dec-20 14-Oct-20 Z614 1 07-Dec-20 14-Oct-20 Z387 1 07-Dec-20 E996 1 07-Dec-20 U689 1 07-Dec-20 - v-janeyg-msft
Community Support
Hi, Anonymous
I really want to help you, and it is not hard to calculate what you want, but your result graph seems to come from excel, which is somewhat different from the matrix of powerbi. Could you share your desired result in PowerBI?
Best Regards
Janey Guo