Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Another Running Total Question

OK I've got a running total measure that works fairly well sort of. 

 

Metric Cumulative = calculate(
    sum('Raw Data'[Component])/[Average Customers],
    Filter(
        Allselected('Raw Data'),
       'Raw Data'[Start Date]<=max('Raw Data'[Start Date])
    )
)

However, when I put this on a line graph, with Year in the legend and Start Date on the axis (but no year or quarter option, straight down to the months), it plots it somewhat strangely. The 2013 data starts at zero and accumulates just fine. But the 2014 data starts in January at the same point that the 2013 data ended at. So the accumulation doesn't start over for each category of the legend. What am I doing wrong?

 

Here's what it looks like currently:

 

And here's what I want it to look like:

 

 

  • Anonymous's avatar
    Anonymous
    8 years ago

    OK turns out this was way easier than I was making it. Instead of messing with the formula and doing everything 'by force', there is a Quick Measure for Year to Date. I thought at the time I was playing with it that the YTD would only work for data in the current year, but it will actually work for multiple years. I was able to add a YTD version of the metric and it worked perfectly and gave me the exact graph I was looking for there.

7 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Anonymous

     

    Give it a shot

     

    Metric Cumulative =
    CALCULATE (
        SUM ( 'Raw Data'[Component] ) / [Average Customers],
        FILTER (
            ALLSELECTED ( 'Raw Data' ),
            'Raw Data'[Start Date] <= MAX ( 'Raw Data'[Start Date] )
                && YEAR ( 'Raw Data'[Start Date] )
                    = YEAR ( SELECTEDVALUE ( 'Raw Data'[Start Date] ) )
        )
    )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hm that didn't work, nothing is plotting at all. I tried adjusting the legend / axis settings but no dice. It's acting as if there are no records where that matches.

       

      I tried setting it to <= and still nothing plotted, but when I set it to >= it plotted the same graph as before. It would need to be = but I don't know why it doesn't work.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous,

    Based on your first screenshot and your sample data, the Metric Cumulative value for January of 2014, 2015, 2016,2017 and 2018 years don't equal to 0, do you want to set the Metric Cumulative value to be 0? If so, could you please share more data of "Raw data" table for us to test?


    Regards,
    Lydia

    • Anonymous's avatar
      Anonymous
      Not applicable

      Right, January wouldn't be equal to 0, but Jan 1st of the year at midnight would be 0.

      Basically my data is very granular, and I have rows of data for almost every hour of every day. I would need it to reset to zero exactly at midnight, but even by 1am on new year's day I'll probably have data. Below is a moderately anonymized version of the table. Dates and stuff are the same. I have calculated columns that don't show here for Year(start date), month(start date), day(Start date). Also have Year&Month (ie 201804), and year month territory (ie 201804A). The customer table also has year month territory column (ie 201804A) which is what the relationship is based on. 

       

      IDStart DateEnd DateStatusMetric Component 2LengthMetric ComponentTerritoryC#UODIDCauseViewSource
      155985834/1/13 0:004/1/13 14:46CMP0886.41666670A839.2634767350.295675Outside FactorPM1.7
      155985844/1/13 0:004/1/13 18:23CMP01103.3833330B3177.05638139.37354854Planned Request CustomerPM1.7
      155985854/1/13 0:214/1/13 1:10CMP24998C36660.452953067.457455Failure WearPM1.7
      155985864/1/13 1:514/1/13 5:06CMP0195.31666670D2694.5550912148.102147Outside Factor FirePM1.7
      155985874/1/13 2:244/1/13 4:45CMP8140.46666671123.73333D6912.509265185.59996Outside Factor FirePM1.7
      155985884/1/13 4:214/1/13 5:50CMP288.26666667176.533333E5885.5579654763.835065AnimalPM1.7
      155985894/1/13 6:194/1/13 6:53CMP133.8666666733.8666667C39680.647736486.94172UnselectedPM1.7
      155985904/1/13 7:184/1/13 9:15CMP1116.6833333116.683333F4205.0159991036.788266AnimalPM1.7
      155985914/1/13 7:204/1/13 7:36CNL115.8515.85Warrensburg6204.304261094.586421UnknownPM1.7
      155985924/1/13 7:214/1/13 9:01CMP099.70C2313.857711892.462309UnselectedPM1.7
      155985934/1/13 7:224/1/13 8:36CMP0740C2284.2550741519.403311UnselectedPM1.7
      155985944/1/13 7:374/12/13 18:00CNL016463.083330A313.0291175156.1489578UnknownPM1.7
      155985954/1/13 7:544/1/13 13:53CMP0358.28333330G18594.872366179.357804 PM1.7
      155985964/1/13 8:084/1/13 11:01CMP1172.6166667172.616667H19719.9154918605.85861 PM1.7
      155985974/1/13 8:104/1/13 12:53CMP0282.650A44.920925229.55197266UnselectedPM1.7
      155985984/1/13 8:134/2/13 12:45CMP01711.60A2765.0360621001.251323Failure WearPM1.7
      155985994/1/13 8:144/1/13 17:40CMP2565.31130.6I2338.265835834.2864042Planned RequestPM1.7
      155986004/1/13 8:154/1/13 11:54CMP02190C25071.0408816298.84957UnselectedPM1.7
      155986014/1/13 8:174/1/13 17:03CMP1525.7666667525.766667J2118.356997414.0393082Planned RequestPM1.7
      155986024/1/13 8:214/1/13 9:16CMP054.10K25165.46525210.0593581Vegetation TreesPM1.7
      155986034/1/13 8:214/3/13 12:59CMP03157.60L7841.8921581030.431465UnselectedPM1.7
      155986044/1/13 8:304/1/13 11:13CMP1162.2162.2G22797.2265810372.7451Failure WearPM1.7
      • Anonymous's avatar
        Anonymous
        Not applicable

        OK turns out this was way easier than I was making it. Instead of messing with the formula and doing everything 'by force', there is a Quick Measure for Year to Date. I thought at the time I was playing with it that the YTD would only work for data in the current year, but it will actually work for multiple years. I was able to add a YTD version of the metric and it worked perfectly and gave me the exact graph I was looking for there.