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
dwilson91
Frequent Visitor

Calculation over time with multiple measures

I STILL NEED HELP IF ANYONE CAN HELP PLEASE...  The ultimate visual I need is a bar chart, not a matrix.  The matrix is just here to show you what results I'm looking for. I wish I could attach my workbook but I don't have that option - sorry!

************************************************************************************************************************

First time poster here.  Not sure if the subject is descriptive of my quandary or if some other post covers this. For that I apologize!  Also, this may be very simple for you but I'm stumped. And for that I apologize again!

 

Here are the context and goal:

I have a data set with work orders for rail tracks that cause trains to slow down, called a slow zone. Each of the work orders has a Date Reported (opened) and a Date Completed (blank if still active) on them. The work orders could originate from different departments at different times, i.e. one could come from construction on the track itself on 1/31/2021, while the other could come from signals on the track on 10/22/22 and both might still be active for two different purposes. So there could be multiple work orders active for the same length of track at the same time. There may also be one work order that was active at one point in time for a length of track but has since been completed, while another is still active. I am trying to show the trend of LENGTH OF TRACK over time that has had ACTIVE work orders on it (ultimately just a bar chart) to show slow zones. Because of this, I don't want to count the length of track multiple times if it had multiple active work orders on it.  I just want to count the length of track once if it had ANY active work order on it at that time.  See below for detailed data and attachments.

 

Here are the details:

I have created two measures for Total Number of Active Slow Zones and Total Length of Active Slow Zones over time using my generic date table as follows:

Total No of Active Slow Zones = 
VAR Currentdate = MAX('Date Table'[Select Date])
var ActiveSlowZones =
Calculate(
    COUNTROWS('Track Speed Limits'),
    all('Date Table'),
    'Date Table'[Select Date]<=Currentdate,
    (isblank('Track Speed Limits'[Date Completed])||'Track Speed Limits'[Date Completed]>=Currentdate)
&&'Track Slow Zones'[Date Reported]<=Currentdate

)
var Result =
if(
    YEAR(Currentdate)<=YEAR(TODAY()),
    ActiveSlowZones
)
RETURN
Result
Total Length of Active Slow Zones = 
VAR Currentdate = MAX('Date Table'[Select Date])
var ActiveSlowZones =
Calculate(
    SUM('Track Speed Limits'[Length]),
    all('Date Table'),
    'Date Table'[Select Date]<=Currentdate,
    (isblank('Track Speed Limits'[Date Completed])||'Track Speed Limits'[Date Completed]>=Currentdate)
&&'Track Slow Zones'[Date Reported]<=Currentdate
)
var Result =
if(
    YEAR(Currentdate)<=YEAR(TODAY()),
    ActiveSlowZones
)
RETURN
Result

But since I don't want to count the length multiple times based on multiple work orders, I tried to simply divide the Total Length by Total Number.  This only works on the rows when I include the Track ID in a matrix, but does not work for the total length.

Total Length by Track ID = [Total Length of Active Slow Zones]/[Total No of Active Slow Zones]

Basically, I want to get the SUM of the Total Length of Active Slow Zones/Total No of Active Slow Zone PER Track ID for each period in time, as is shown below:

dwilson91_0-1684256118797.png

Since I'm not able to attach anything, I'm pasting some sample data below.

 

Work OrderTrack IDLengthSZ StatusOwning AreaDate ReportedDate Completed
9900000TRK01114In EffectTRACK4/4/2023 
9900001TRK02109In EffectTRACK4/4/2023 
9900004TRK05259Closed/CompletedCONST3/21/20233/24/2023
9900005TRK06260In EffectSIGNAL1/11/2022 
9900006TRK06260Closed/CompletedCONST3/29/20233/31/2023
9900007TRK07260In EffectCONST3/14/2023 
9900008TRK07260Closed/CompletedCONST2/28/20233/6/2023
9900009TRK08259Closed/CompletedCONST3/14/20233/21/2023
9900010TRK08259Closed/CompletedCONST2/28/20233/6/2023
9900042TRK37176In EffectTRACK6/25/2021 
9900043TRK38226In EffectTRACK9/15/2014 
9900044TRK39555In EffectTRACK11/1/2019 
9900045TRK40231In EffectTRACK10/6/2022 
9900046TRK41206In EffectTRACK6/22/2021 
9900047TRK41206In EffectSIGNAL6/15/2016 
9900048TRK42150In EffectTRACK5/17/2019 
9900049TRK42150In EffectTRACK2/15/2018 
9900050TRK43150In EffectTRACK3/9/2016 
9900051TRK44257Closed/CompletedTRACK12/28/202110/26/2022
9900052TRK44257Closed/CompletedSIGNAL10/18/202110/26/2022

 

Thanks in advance for any help you can provide!

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @dwilson91,

It seems like a common multiple aggregate calculate issue. I'd like to suggest you refer to the following blog to add a variable with summarize function to calculate expression on the detail level and use iterator function to summary previous calculation results.

Measure Totals, The Final Word 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @dwilson91,

It seems like a common multiple aggregate calculate issue. I'd like to suggest you refer to the following blog to add a variable with summarize function to calculate expression on the detail level and use iterator function to summary previous calculation results.

Measure Totals, The Final Word 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks, Xiaoxin @v-shex-msft 

I appreciate your response and your suggestion.  While that seems to make sense, the problem I have is that it is in the context of OVER TIME. The measures calculate active slow zones on Track ID per month/year.  The slow zone can be open for several months or years, so I want to count that Track ID for each month that it's active.  Because of that, I don't know how to embed this suggestion into my measures over time.  Also, my intention is not to use the table, but to take the measures and use them in a bar chart, so I will not have detailed Track IDs in the visual.  I'm just using it now in this thread to show the calculation I'm trying to achieve.

dwilson91
Frequent Visitor

@Greg_Deckler Hi Greg. Do you know how I can get an answer to this?  Did I do something wrong in my post?

dwilson91
Frequent Visitor

@amitchandak Any chance you might be able to help me with this?

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.