Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      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 
      • v-janeyg-msft's avatar
        v-janeyg-msft
        Icon for Community Support rankCommunity 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