Forum Discussion
Multiple group by/ranking issue
I have a faily simple data issue, which seems like it could be complicated in Power BI, but I'm a relative newbie so I'm hoping someone can point me in the right direction.
Here's the overview: I have data which includes multiple plants, each plant has multiple wind turbines, and each turbine has multiple alarms which go off on a daily basis. What I need to do is this:
1. Count how many alarms went off per plant per day, by alarm type.
2. Find the top n (in this simple case n = 2) alarms, by plant, for any date range the user selects.
3. Once we know which were the top 2 alarms for each plant, we need to then figure out which turbine(s) had the most instances of that alarm go off in the same time period.
4. The final output is basically Plant Name, Alarm Code, # of alarms, and Turbine(s) most impacted. That would look like this:
Here's how the data flow would work from start to finish:
First, the raw data. This is just 2 days with 2 plants, 3 alarms and 3 turbines per plant:
So the next step is to count total number of alarms per plant for the given date range. Ultimately, we only care about the top 2 for each plant:
We now need to count the total number of alarms per turbine, to know which match up with our most common alarms:
Now we need only those which were part of the most common alarms (AC1, AC2):
And then again, the final data set which shows the most common alarms per plant, with a column for the turbine(s) which were most affected by those alarms:
I feel like this shouldn't be too difficult to do, it took about 2 minutes wo work up Access queries to show the data I need, but the tricky part is dealing with selecting any date range to begin with. In my example here it's just 2 days and I selected them both, but in reality we'll have year(s) worth of data and the user should use a slider to pick any date range they want, and then these same calculations need to happen.
Thank you so much if you can help!
thanks
Alex
AnonymousHere is what I am doing,
1)Create a measure called "Rank Alarm Code" using following code :
Rank Alarm Code = RANKX(ALLSELECTED(Sheet1[Alarm_Code]),CALCULATE(sum(Sheet1[Alarm_Count]),ALLSELECTED(Sheet1[Turbine])),, DESC)
2)Create another measure called "Rank Turbines" using following code :Rank Turbine = RANKX(ALLSELECTED(Sheet1[Turbine]),CALCULATE(SUM(Sheet1[Alarm_Count])))
3)Create one more measure called "Total Alarms" using following code:Total Alarms = CALCULATE(SUM(Sheet1[Alarm_Count]),ALL(Sheet1[Turbine]))
4) Filter (visual/Report/Page) on "Rank alarm Code"<=25) Filter (visual/Report/Page) on "Rank Turbine"=1
6)Add "Total Alarms" to the report.
You should get output as shown in the screen shot.
I am also trying to explore PowerBI more, please correct me if i misunderstood your requirement. I was unable to upload PBX as i don't have permissions.
Hi,
You may download my PBI file from here. For Plant 2, AC3 should also show up because of a tie - 32 alarms.
Hope this helps.
- Anonymous7 years ago
Wow! This is fantastic, thank you so much!
14 Replies
- Greg_DecklerCommunity Champion
Seems doable, but I am not typing in all of that data into Power BI Desktop to figure it out. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
- AnonymousNot applicable
I just got back to my desk and haven't followed that link yet (but surely will, thank you!), but assume you want the data - I should have thought of that. Attached is a spreadsheet with the original base data, as well as all of the data used in my prior images. Hopefully that helps, and if it does, thank you very much!
Alex
p.s. I couldn't figure how to upload an Excel file so I did read the above post on how to get the best possible answer, so I'll paste from excel below and hope for the best...
Raw Data Plant Date Alarm_Code Turbine Alarm_count Plant1 1/1/2018 AC1 T1 5 Plant1 1/1/2018 AC1 T2 1 Plant1 1/1/2018 AC1 T3 7 Plant1 1/1/2018 AC2 T1 1 Plant1 1/1/2018 AC2 T2 10 Plant1 1/1/2018 AC2 T3 3 Plant1 1/1/2018 AC3 T1 1 Plant1 1/1/2018 AC3 T2 10 Plant1 1/1/2018 AC3 T3 3 Plant1 1/2/2018 AC1 T1 21 Plant1 1/2/2018 AC1 T2 0 Plant1 1/2/2018 AC1 T3 12 Plant1 1/2/2018 AC2 T1 5 Plant1 1/2/2018 AC2 T2 9 Plant1 1/2/2018 AC2 T3 1 Plant1 1/2/2018 AC3 T1 1 Plant1 1/2/2018 AC3 T2 2 Plant1 1/2/2018 AC3 T3 5 Plant2 1/1/2018 AC1 T1 6 Plant2 1/1/2018 AC1 T2 15 Plant2 1/1/2018 AC1 T3 14 Plant2 1/1/2018 AC2 T1 6 Plant2 1/1/2018 AC2 T2 15 Plant2 1/1/2018 AC2 T3 2 Plant2 1/1/2018 AC3 T1 8 Plant2 1/1/2018 AC3 T2 6 Plant2 1/1/2018 AC3 T3 14 Plant2 1/2/2018 AC1 T1 20 Plant2 1/2/2018 AC1 T2 17 Plant2 1/2/2018 AC1 T3 8 Plant2 1/2/2018 AC2 T1 4 Plant2 1/2/2018 AC2 T2 20 Plant2 1/2/2018 AC2 T3 20 Plant2 1/2/2018 AC3 T1 5 Plant2 1/2/2018 AC3 T2 3 Plant2 1/2/2018 AC3 T3 18 Top 2 Alarms by plant Plant Alarm_Code Alarm_count Plant1 AC1 46 Plant1 AC2 29 Plant1 AC3 22 Plant2 AC1 80 Plant2 AC2 67 Plant2 AC3 54 All alarms by Turbine Plant Turbine Alarm_Code Alarm_Count Plant1 T1 AC1 26 Plant1 T1 AC2 6 Plant1 T1 AC3 2 Plant1 T2 AC1 1 Plant1 T2 AC2 19 Plant1 T2 AC3 12 Plant1 T3 AC1 19 Plant1 T3 AC2 4 Plant1 T3 AC3 8 Plant2 T1 AC1 26 Plant2 T1 AC2 10 Plant2 T1 AC3 13 Plant2 T2 AC1 32 Plant2 T2 AC2 35 Plant2 T2 AC3 9 Plant2 T3 AC1 22 Plant2 T3 AC2 22 Plant2 T3 AC3 32 Join turbine data back to top alarms to find most impacted Turbines Plant Alarm_Code Turbine TotalAlarms TurbineAlarms Plant1 AC1 T1 46 26 Plant1 AC1 T3 46 19 Plant1 AC1 T2 46 1 Plant1 AC2 T2 29 19 Plant1 AC2 T1 29 6 Plant1 AC2 T3 29 4 Plant2 AC1 T2 80 32 Plant2 AC1 T1 80 26 Plant2 AC1 T3 80 22 Plant2 AC2 T2 67 35 Plant2 AC2 T3 67 22 Plant2 AC2 T1 67 10 Final dataset Plant Alarm_Code TotalAlarms Most impacted Turbine(s) Plant1 AC1 46 T1 Plant1 AC2 29 T2 Plant2 AC1 80 T2 Plant2 AC2 67 T2 - itsmebvkContinued Contributor
AnonymousHere is what I am doing,
1)Create a measure called "Rank Alarm Code" using following code :
Rank Alarm Code = RANKX(ALLSELECTED(Sheet1[Alarm_Code]),CALCULATE(sum(Sheet1[Alarm_Count]),ALLSELECTED(Sheet1[Turbine])),, DESC)
2)Create another measure called "Rank Turbines" using following code :Rank Turbine = RANKX(ALLSELECTED(Sheet1[Turbine]),CALCULATE(SUM(Sheet1[Alarm_Count])))
3)Create one more measure called "Total Alarms" using following code:Total Alarms = CALCULATE(SUM(Sheet1[Alarm_Count]),ALL(Sheet1[Turbine]))
4) Filter (visual/Report/Page) on "Rank alarm Code"<=25) Filter (visual/Report/Page) on "Rank Turbine"=1
6)Add "Total Alarms" to the report.
You should get output as shown in the screen shot.
I am also trying to explore PowerBI more, please correct me if i misunderstood your requirement. I was unable to upload PBX as i don't have permissions.