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
soldstatic
Resolver I
Resolver I

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:

Cumulative.png

 

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

Cumulative Should Be.png

 

 

1 ACCEPTED SOLUTION

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.

View solution in original post

7 REPLIES 7
v-yuezhe-msft
Employee
Employee

@soldstatic,

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

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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

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.

Zubair_Muhammad
Community Champion
Community Champion

@soldstatic

 

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] ) )
    )
)

Regards
Zubair

Please try my custom visuals

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.

@soldstatic

 

Could you share your file?


Regards
Zubair

Please try my custom visuals

Unfortunately no I can't, it has some sensitive data.

 

The format is something like this:

Customer Count Table:

TerritoryCustomersYearMonthYearMon
A37,381.00201712201712
B47,416.00201712201712
C10,106.00201712201712
D109,685.00201712201712
E64,144.00201712201712
F9,551.00201712201712
G152,264.00201712201712
H61,934.00201712201712
I20,968.00201712201712
J10,536.00201712201712
K14,323.00201712201712
L7,801.00201712201712
M101,184.00201712201712
N30,221.00201712201712
O17,931.00201712201712
P15,918.00201712201712
Q83,562.00201712201712
R49,529.00201712201712
S2,844.00201712201712
T21,332.00201712201712
A37,452.002018120181
B47,483.002018120181
C10,108.002018120181
D109,898.002018120181
E64,600.002018120181
F9,548.002018120181
G152,249.002018120181
H61,999.002018120181
I20,983.002018120181
J10,530.002018120181
K14,327.002018120181
L7,804.002018120181
M105,975.002018120181
N30,184.002018120181
O18,001.002018120181
P15,908.002018120181
Q83,549.002018120181
R49,557.002018120181
S2,835.002018120181
T21,348.002018120181
A10,512.002018320183
B14,583.002018320183
C7,795.002018320183
D105,777.002018320183
E30,154.002018320183
F18,058.002018320183
G15,895.002018320183
H83,514.002018320183
I49,475.002018320183
J2,826.002018320183
K21,353.002018320183
L37,498.002018320183
M47,551.002018320183
N10,104.002018320183
O109,784.002018320183
P64,638.002018320183
Q9,586.002018320183
R152,341.002018320183
S62,076.002018320183
T21,019.0020183

20183

 

 

Event Table:

Event Table

EventMetric ComponentDate/TimeYear-Mon
1101/1/2018 5:30AM2018-1
2421/3/2018 5:30AM2018-1
354312/1/2018 5:30AM2018-2
42492/1/2018 6:30AM2018-2

 

My Average Customer formula is:

Average Customers Served = AVERAGEX(
    summarize('Customers by Center',
        'Customers by Center'[Year],
        'Customers by Center'[Month],
        "CustomSum", SUM('Customers by Center'[Customers])
        ),
        [CustomSum]
        )

The Metric (non cumulative version) is:

Metric = sum('Raw Data'[Component])/[Average Customers Served]

And that works great, except that I'm wanting a graph that will show the month to month accumulation by year, and then I want to be able to drill into that line graph to see the day to day accumulation by month. I just can't get the Cumulative component to split based on year. The SelectedValue, do you think it's returning more than one element? Is that why it isn't returning anything at all when I specify <= or = year in the formula you provided? I think that methodology should work, but I'm not very familiar with how SelectedValue() works

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.