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
leroy773
Helper II
Helper II

Calculate percentage based on rolling sum of products vs the part replacements

All,

 

I am not sure if it is even possible, but I am trying to track a percentage of parts replacement based on rolling sum of three to four months, and how many parts were replaced during a certain month.

 

The chart below has serial number which shows up each time a part is replaced for that serial number.  I am trying to sum the number of serial numbers without including duplicates based on date installed.  Such that, in March I would like to i would like for the sum to be 17 products.  Then I would like to find the percentage of components changed in the month of March for that total of 17.

 

If that does not make it more confusing enough, I would like to for the report to only use the number of part replacements associated with the serial number in the rolling sum.  Such if an item was install in December and in come 8 months later a part was replaced, would not like to ensure that does not show up in the computation.

 

Not sure if thisis feasible or I communicated it correctly.

 

 

 

Serial NumberDate/Time OpenedComponent Level 2Date Installed
111/3/2016 9:20A12/4/2015
21/22/2016 15:07A12/23/2015
28/23/2016 9:35A12/23/2015
28/30/2016 15:48B12/23/2015
312/8/2015 14:43B12/23/2015
33/22/2016 13:51B12/23/2015
34/29/2016 14:21C12/23/2015
42/16/2016 15:28A12/24/2015
51/22/2016 15:07C1/8/2016
54/19/2016 15:53C1/8/2016
62/24/2016 9:12A1/12/2016
71/22/2016 15:08A1/15/2016
72/4/2016 14:17A1/15/2016
77/7/2016 13:38A1/15/2016
86/1/2016 3:41A3/8/2016
98/4/2016 4:57B3/10/2016
107/22/2016 13:23B3/18/2016
114/8/2016 6:56B3/19/2016
116/29/2016 15:14B3/19/2016
128/30/2016 17:27C3/23/2016
132/8/2016 17:47C3/28/2016
136/22/2016 23:15C3/28/2016
137/26/2016 19:19D3/28/2016
138/18/2016 21:46D3/28/2016
149/7/2016 3:19A3/30/2016
157/20/2016 14:18A3/31/2016
163/7/2016 13:08A3/31/2016
178/12/2016 11:59A4/13/2016
188/29/2016 15:51A4/26/2016
198/15/2016 0:29B5/5/2016
206/27/2016 1:49B5/14/2016
217/4/2016 6:38B6/10/2016
2210/7/2016 5:56C7/5/2016
238/25/2016 10:08C8/11/2016
2411/14/2016 10:07C9/15/2016
1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @leroy773,


Based on my understanding, components changed is changed if the Serial Number and Date Installed are same, which the Date/Time Opened is different. You want to calculate the percentage of components changed in each month for the total, right? If it is, I try to reproduce the following solution and get expected result.

First, you should find the changed component. Add an index column, lookup the previous row value and compare them using the formula below. Create a tag column to return whether the component is changed.

In power bi desktop go to query editor, click Add column->Index column, you will get the index column.

 

Month = Test[Date Installed].[Month]
Lastnumber = LOOKUPVALUE(Test[Serial Number],Test[Index],Test[Index]-1)
Lastopen = LOOKUPVALUE(Test[Date/Time Opened],Test[Index],Test[Index]-1)
Lastinstall = LOOKUPVALUE(Test[Date Installed],Test[Index],Test[Index]-1)
Tag = IF(Test[Serial Number]=Test[Lastnumber]&&Test[Date Installed]=Test[Lastinstall],IF(Test[Date/Time Opened]<>Test[Lastopen],1,0),0)

 

 

Then, create measures to calculate the total and percentage.

Changed = CALCULATE(DISTINCTCOUNT(Test[Tag]),ALLEXCEPT(Test,Test[Month]))
Total = CALCULATE(DISTINCTCOUNT(Test[Serial Number]),ALLEXCEPT(Test,Test[Month]))
Percentage = Test[Changed]/Test[Total]


1.png 

Finally, create a table, select the month as axis, the measures as value levels, you will get the expected result.

2.png

 

If you have any question, please feel free to ask.

Best Regards,
Angelia

View solution in original post

1 REPLY 1
v-huizhn-msft
Employee
Employee

Hi @leroy773,


Based on my understanding, components changed is changed if the Serial Number and Date Installed are same, which the Date/Time Opened is different. You want to calculate the percentage of components changed in each month for the total, right? If it is, I try to reproduce the following solution and get expected result.

First, you should find the changed component. Add an index column, lookup the previous row value and compare them using the formula below. Create a tag column to return whether the component is changed.

In power bi desktop go to query editor, click Add column->Index column, you will get the index column.

 

Month = Test[Date Installed].[Month]
Lastnumber = LOOKUPVALUE(Test[Serial Number],Test[Index],Test[Index]-1)
Lastopen = LOOKUPVALUE(Test[Date/Time Opened],Test[Index],Test[Index]-1)
Lastinstall = LOOKUPVALUE(Test[Date Installed],Test[Index],Test[Index]-1)
Tag = IF(Test[Serial Number]=Test[Lastnumber]&&Test[Date Installed]=Test[Lastinstall],IF(Test[Date/Time Opened]<>Test[Lastopen],1,0),0)

 

 

Then, create measures to calculate the total and percentage.

Changed = CALCULATE(DISTINCTCOUNT(Test[Tag]),ALLEXCEPT(Test,Test[Month]))
Total = CALCULATE(DISTINCTCOUNT(Test[Serial Number]),ALLEXCEPT(Test,Test[Month]))
Percentage = Test[Changed]/Test[Total]


1.png 

Finally, create a table, select the month as axis, the measures as value levels, you will get the expected result.

2.png

 

If you have any question, please feel free to ask.

Best Regards,
Angelia

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.