Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
RolandoLara
Frequent Visitor

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:

Days Late Formulas.png

output 1.png

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.

other outputs.png

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 9
littlemojopuppy
Community Champion
Community Champion

Hola!  Can you provide some sample data to play with?

Here you go. Thanks!

Order IDQtyTarget DateActual Date
F272101-Oct-20 
P775101-Oct-20 
J598101-Oct-2016-Nov-20
K954101-Oct-20 
U338101-Oct-20 
D543301-Oct-20 
N242301-Oct-2016-Nov-20
V501101-Oct-20 
R574102-Oct-20 
V236102-Oct-20 
G427103-Oct-2010-Oct-20
Y504103-Oct-2010-Oct-20
R207103-Oct-2002-Oct-20
L210103-Oct-2027-Nov-20
B380104-Oct-20 
Y816104-Oct-20 
X937107-Oct-20 
K773107-Oct-20 
S429107-Oct-2023-Oct-20
Z572107-Oct-20 
P171107-Oct-20 
A405123-Oct-20 
S280123-Oct-2029-Sep-20
X417124-Oct-2008-Oct-20
V452124-Oct-2005-May-20
X965124-Oct-2020-Jun-16
A380124-Oct-2019-Oct-20
C296124-Oct-2016-Oct-20
F963124-Oct-2016-Oct-20
C785124-Oct-2029-Oct-20
F757124-Oct-2029-Oct-20
P733124-Oct-2016-Oct-20
D234124-Oct-2016-Oct-20
D494124-Oct-2023-Oct-20
X101124-Oct-2016-Oct-20
X234124-Oct-2023-Oct-20
Z570125-Oct-2025-Sep-20
S556225-Oct-2022-Oct-20
D353225-Oct-2026-Oct-20
E653225-Oct-2026-Oct-20
R579225-Oct-2008-Oct-20
R477425-Oct-2016-Oct-20
U203525-Oct-20 
P617130-Oct-20 
M376130-Oct-2027-Aug-20
S183130-Oct-2027-Aug-20
W158130-Oct-2005-Nov-20
K613130-Oct-20 
N647130-Oct-20 
O125130-Oct-20 
K996130-Oct-20 
J357130-Oct-2005-Nov-20
O550130-Oct-2005-Nov-20
V826130-Oct-2005-Nov-20
N871130-Oct-20 
E879330-Oct-20 
U715131-Oct-2014-Nov-20
Y979131-Oct-2014-Nov-20
M959131-Oct-20 
T426131-Oct-2027-Oct-20
P801131-Oct-2027-Oct-20
S333131-Oct-20 
K921131-Oct-20 
R657231-Oct-20 
Z457231-Oct-2027-Oct-20
G870831-Oct-2027-Oct-20
T25L131-Oct-20 
B374107-Nov-20 
E911107-Nov-20 
L250107-Nov-20 
D434107-Nov-2011-Nov-20
Y522107-Nov-2011-Nov-20
F649107-Nov-2028-Oct-20
L495107-Nov-2021-Oct-20
Q345107-Nov-20 
Y179113-Nov-20 
B509113-Nov-20 
H741113-Nov-20 
J446114-Nov-2018-Oct-20
Z144119-Nov-2013-Nov-20
B721119-Nov-2013-Nov-20
I986119-Nov-20 
E428119-Nov-2013-Nov-20
M829120-Nov-20 
O345123-Nov-20 
Z697123-Nov-2015-Oct-20
R529123-Nov-2001-Oct-20
M349123-Nov-2001-Oct-20
B838123-Nov-2001-Oct-20
A536123-Nov-20 
G4911124-Nov-20 
A5151224-Nov-2023-Nov-20
T102125-Nov-20 
P322125-Nov-2026-Oct-20
M138125-Nov-20 
Y817130-Nov-20 
L859130-Nov-2027-Nov-20
Q380130-Nov-20 
W615130-Nov-2027-Nov-20
Y402130-Nov-20 
I873630-Nov-20 
S807730-Nov-2016-Nov-20
K225530-Nov-2023-Nov-20
S358130-Nov-20 
I639105-Dec-2029-Oct-20
G757106-Dec-20 
Y978107-Dec-2031-Aug-20
C689107-Dec-20 
J778107-Dec-20 
Z758107-Dec-2014-Oct-20
Z614107-Dec-2014-Oct-20
Z387107-Dec-20 
E996107-Dec-20 
U689107-Dec-20 

Hi, @RolandoLara 

 

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?

4.png

Best Regards

Janey Guo

Hello! Thank you so much for your response!

 

There are different outputs that I am trying to achieve.

 

1.-The first one is the one you have in your post (without the subtotals). (Output 1)

 

2.- Another output would be the same matrix but, when the value is >0  then enter the Order quantity for each month. (Output 2). This tells me the quantity of items late in each month in each order.

2A.- Assume there is another column called plant. Then I would like to have a matrix (Output 2A) where the rows are the plant, the columns are the month end date, and the values are the sum of the output I just described (output 2). This will tell me the total of units late in each plant at the end of each month.

 

3.- The third output (Output III) would be the the same structure of the table you have produced (Output I) but the value should be multiplied by the quantity in the order. This is to account the number of units in each order to calculate the lateness (days late, per unit, not per order)

3A.- Assume there is another column called plant. Then I would like to have a matrix (Output 3A) where the rows are plant, the columns are the month end date, and the values are the sum of the output Idescribed in point 3 (output 3). This will tell me the total number of days late at the end of each month per plant.

 

4.- Last output would be a Matrix where rows are the plants, columns are the month end dates, and the values are the Output 3A divided by Output 2A. This will tell me the average number of days late per unit that each plant has at the end of each month.

 

I hope this helps. Else, I can draw something in excel. I am sorry I am not being able to do tis in Power BI right now, that is why I am asking for help at the moment.

 

Thanks,

 

R

Hi, @RolandoLara 

 

I understand your question and it is not hard to do it, but the problem is visual! Your result graphs are displayed in excel, but the matrix in PBI will cause some problems.The first four columns placed in the matrix's row will inevitably be displayed hierarchically, then only one line will be displayed if it is not expanded, and a lot of 'total' will be displayed if expanded. If 'total' is turned off, the total 'total' is gone. Can you show the result graphs in PBI visual?So we can help you soon.

 

Best Regards

Janey Guo

Hello! Was the information supplied useful? Please let me know if you need any more information.

Thanks,

 

Hi, @RolandoLara 

 

If you want to use table visual to make exactly the same renderings that you show on excel, you will inevitably need to create a lot of columns, as you said before.

If you use matrix visual, you can create a separate table, but using matrix to put multiple columns in the row will cause the problem I mentioned before.

What visual display do you want to use? It’s not difficult to calculate the result, but you need to determine the presentation.

 

Best Regards

Janey Guo

These are the visualizations I am looking for. I made all my calculations in excel except of the last one - which is a measure. I had to create a column for a value for each month end, which is what I am trying to avoid - it is not sustainable. Let me know if this is what you need to provide some help. Thanks!

Capture.PNGCapture2.PNG

Hello - I created a new data set for the example to be better. I am having issues with the table feature, please paste and use space as separator. BI visualizations coming in next post. 

 

Order_ID Plant Target_Date Actual_Date Quantity
F272 A 14-Nov-19 1
P775 A 01-Sep-20 1
J598 A 05-Mar-20 11/16/2020 1
K954 B 03-May-20 1
U338 B 16-Nov-19 1
D543 B 03-Jul-20 3
N242 C 01-Oct-20 11/16/2020 3
V501 C 04-Jul-20 1
R574 C 14-Feb-20 1
V236 D 02-Mar-20 1
G427 D 23-Mar-20 10/10/2020 1
Y504 D 10-Jul-20 10/10/2020 1
R207 B 13-Aug-20 10/2/2020 1
L210 B 13-Oct-19 11/27/2020 1
B380 B 04-Aug-20 1
Y816 B 03-Apr-20 1
X937 C 29-Jun-20 1
K773 C 13-Sep-20 1
S429 C 23-Mar-20 10/23/2020 1
Z572 D 10-Aug-20 1
P171 D 08-Feb-20 1
A405 D 03-Jun-20 1
S280 D 27-Mar-20 9/29/2020 1
X417 D 22-Nov-19 10/8/2020 1
V452 A 11-Feb-20 5/5/2020 1
X965 A 26-May-20 6/20/2016 1
A380 A 28-Aug-20 10/19/2020 1
C296 A 31-Dec-19 10/16/2020 1
F963 D 20-Jul-20 10/16/2020 1
C785 D 10-Jul-20 10/29/2020 1
F757 D 19-Jul-20 10/29/2020 1
P733 D 15-Jun-20 10/16/2020 1
D234 C 18-Apr-20 10/16/2020 1
D494 C 1/25/2020 10/23/2020 1
X101 C 12/30/2019 10/16/2020 1
X234 C 2/10/2020 10/23/2020 1
Z570 B 2/17/2020 9/25/2020 1
S556 B 3/10/2020 10/22/2020 2
D353 B 11/23/2019 10/26/2020 2
E653 B 9/10/2020 10/26/2020 2
R579 B 7/26/2020 10/8/2020 2
R477 A 5/4/2020 10/16/2020 4
U203 A 1/21/2020 5
P617 A 5/4/2020 1
M376 A 2/7/2020 8/27/2020 1
S183 A 5/27/2020 8/27/2020 1
W158 A 12/29/2019 11/5/2020 1
K613 A 1/1/2020 1
N647 A 7/18/2020 1
O125 B 6/10/2020 1
K996 B 5/12/2020 1
J357 B 7/12/2020 11/5/2020 1
O550 B 6/1/2020 11/5/2020 1
V826 C 7/14/2020 11/5/2020 1
N871 C 2/8/2020 1
E879 C 6/28/2020 3
U715 C 6/4/2020 11/14/2020 1
Y979 D 4/29/2020 11/14/2020 1
M959 D 12/12/2019 1
T426 D 11/4/2019 10/27/2020 1
P801 D 8/21/2020 10/27/2020 1
S333 A 3/22/2020 1
K921 A 10/5/2020 1
R657 A 3/12/2020 2
Z457 A 12/21/2019 10/27/2020 2
G870 A 2/18/2020 10/27/2020 8
T25L B 10/4/2020 1
B374 B 9/29/2020 1
E911 B 3/11/2020 1
L250 C 8/14/2020 1
D434 C 7/21/2020 11/11/2020 1
Y522 C 12/9/2019 11/11/2020 1
F649 B 5/28/2020 10/28/2020 1
L495 B 2/26/2020 10/21/2020 1
Q345 B 11/22/2019 1
Y179 A 7/11/2020 1
B509 A 9/17/2020 1
H741 A 8/23/2020 1
J446 D 9/19/2020 10/18/2020 1
Z144 D 8/1/2020 11/13/2020 1
B721 D 5/13/2020 11/13/2020 1
I986 C 5/11/2020 1
E428 C 12/2/2019 11/13/2020 1
M829 C 12/2/2019 1
O345 A 4/9/2020 1
Z697 A 1/28/2020 10/15/2020 1
R529 A 3/25/2020 10/1/2020 1
M349 B 9/2/2020 10/1/2020 1
B838 B 11/7/2020 10/1/2020 1
A536 A 2/8/2020 1
G491 A 3/3/2020 11
A515 A 9/11/2020 11/23/2020 12
T102 A 9/10/2020 1
P322 A 4/20/2020 10/26/2020 1
M138 A 8/12/2020 1
Y817 A 3/23/2020 1
L859 A 6/6/2020 11/27/2020 1
Q380 A 12/20/2019 1
W615 A 1/28/2020 11/27/2020 1
Y402 A 5/2/2020 1
I873 A 2/7/2020 6
S807 B 7/27/2020 11/16/2020 7
K225 B 1/18/2020 11/23/2020 5
S358 B 8/22/2020 1
I639 B 1/15/2020 10/29/2020 1
G757 B 1/27/2020 1
Y978 B 7/4/2020 8/31/2020 1
C689 D 5/5/2020 1
J778 D 6/9/2020 1
Z758 D 3/5/2020 10/14/2020 1
Z614 D 1/21/2020 10/14/2020 1
Z387 D 8/7/2020 1
E996 D 1/22/2020 1
U689 D 10/16/2020 1

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.