Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

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:

 

most impacted turbines.png

 

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:

raw data.png

 

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:

alarms per plant.png

 

We now need to count the total number of alarms per turbine, to know which match up with our most common alarms:

turbine and alarm count.png

 

 

Now we need only those which were part of the most common alarms (AC1, AC2):

alarms and turbines.png

 

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:

most impacted turbines.png

 

 

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

 

3 ACCEPTED SOLUTIONS
itsmebvk
Continued Contributor
Continued Contributor


@Anonymous

 

Here 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"<=2

5) 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.

 

Output.PNG

 

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.

View solution in original post

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.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Anonymous
Not applicable

Wow! This is fantastic, thank you so much!

View solution in original post

14 REPLIES 14
Greg_Deckler
Community Champion
Community 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



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not 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
PlantDateAlarm_CodeTurbineAlarm_count
Plant11/1/2018AC1T15
Plant11/1/2018AC1T21
Plant11/1/2018AC1T37
Plant11/1/2018AC2T11
Plant11/1/2018AC2T210
Plant11/1/2018AC2T33
Plant11/1/2018AC3T11
Plant11/1/2018AC3T210
Plant11/1/2018AC3T33
Plant11/2/2018AC1T121
Plant11/2/2018AC1T20
Plant11/2/2018AC1T312
Plant11/2/2018AC2T15
Plant11/2/2018AC2T29
Plant11/2/2018AC2T31
Plant11/2/2018AC3T11
Plant11/2/2018AC3T22
Plant11/2/2018AC3T35
Plant21/1/2018AC1T16
Plant21/1/2018AC1T215
Plant21/1/2018AC1T314
Plant21/1/2018AC2T16
Plant21/1/2018AC2T215
Plant21/1/2018AC2T32
Plant21/1/2018AC3T18
Plant21/1/2018AC3T26
Plant21/1/2018AC3T314
Plant21/2/2018AC1T120
Plant21/2/2018AC1T217
Plant21/2/2018AC1T38
Plant21/2/2018AC2T14
Plant21/2/2018AC2T220
Plant21/2/2018AC2T320
Plant21/2/2018AC3T15
Plant21/2/2018AC3T23
Plant21/2/2018AC3T318

 

 

Top 2 Alarms by plant
PlantAlarm_CodeAlarm_count
Plant1AC146
Plant1AC229
Plant1AC322
Plant2AC180
Plant2AC267
Plant2AC354

 

 

All alarms by Turbine
PlantTurbineAlarm_CodeAlarm_Count
Plant1T1AC126
Plant1T1AC26
Plant1T1AC32
Plant1T2AC11
Plant1T2AC219
Plant1T2AC312
Plant1T3AC119
Plant1T3AC24
Plant1T3AC38
Plant2T1AC126
Plant2T1AC210
Plant2T1AC313
Plant2T2AC132
Plant2T2AC235
Plant2T2AC39
Plant2T3AC122
Plant2T3AC222
Plant2T3AC332

 

 

Join turbine data back to top alarms to find most impacted Turbines
PlantAlarm_CodeTurbineTotalAlarmsTurbineAlarms
Plant1AC1T14626
Plant1AC1T34619
Plant1AC1T2461
Plant1AC2T22919
Plant1AC2T1296
Plant1AC2T3294
Plant2AC1T28032
Plant2AC1T18026
Plant2AC1T38022
Plant2AC2T26735
Plant2AC2T36722
Plant2AC2T16710

 

 

Final dataset
PlantAlarm_CodeTotalAlarmsMost impacted Turbine(s)
Plant1AC146T1
Plant1AC229T2
Plant2AC180T2
Plant2AC267T2

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.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Ashish_Mathur I've started converting the work you did (thanks again, this is so helpful!) into a more realistic data set, changing column names to what I need them to be, etc. and I notice one issue and can't figure out how to fix it. I've uploaded a new copy of the .pbix here: https://drive.google.com/drive/folders/1al0BHPaSDibkgi5Axxgm_aIILKZLo0jE

 

My problem is that for plant2, the "test" filter, which is supposed to only show the top ranked turbines, returns a 0 for the top ranked turbines in this case. Alarm 4110 is correctly ranked #1, but none of the turbines which use that alarm are listed. Realistically, all 3 of them should have test = 1, as those are tied to the top ranked alarm. Any ideas you have are much appreciated, I can't quite figure it out. Thank you!

 

alarms.png

 

Hi,

 

That weblink reads "You need permission".


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

So I believe I've found the problem, but haven't yet found the solution. In "Top 2 Turbines 4.pbix" which can be found here: https://drive.google.com/drive/folders/1al0BHPaSDibkgi5Axxgm_aIILKZLo0jE

 

I noticed that one plant with many turbines works fine if I only select that specific alarm code, as shown below - it does correctly pick the only turbine which has that alarm twice:

 

alarm 1.png

 

And if I add another alarm which doesn't use any of the same turbines, such as 3661, it still works:

 

alarm 2.png

 

But if I choose an alarm which ONLY uses one of the turbines that's also part of 3634, then my "highest number of alarms at Alarm_code level" incorrectly goes to 3, which breaks the test filter.

 

alarm 3.png

 

So it seems to me that "highest number of alarms at Alarm_code level" needs some type of filter to only associate the alarms with the correct turbines, or vice versa. I'm still trying to understand precisely how these measures work, I may be able to figure this one out now that I see the problem, but if you have time to take a look it's much appreciated! This is a big project and I really need to get this done ASAP.

 

thanks again!

Alex

Hi,

 

See if this helps.  Download the PBI file from here.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Unfortunately that doesn't do it, now the "test" column is broken, and "highest number of alarms at alarm code level" is off in some cases. That value should be 2 for all of the 3634 rows, since turbine F09 has 2 of those alarms. If that column did have 2 in it, then our test which compares the highest column to number of alarms would only be true for F09, which is what we want. But now it's true for all of them. It's also now wrong for 3674.

 

I'll keep looking at it and see if I can make it work given these new changes. Thanks again for trying, and if you have any other ideas I certainly appreciate it!

Hi,

 

Does this work?

 

Highest number of alarms at Alrm_code level = MAXX(TOPN(1,ALL(top_alarms[turbine_code]),[Number of alarms]),[Number of alarms])

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

I will try it but I don't think it will work, as the problem seems to be with the Highest number of alarms at Alrm_code level measure, as described 2 posts back, where it increases to 3 when another turbine is introduced with the same alarm code, even though there are only 2 alarms on one turbine from 3634, not 3. It seems to me that the test measure will work correctly if I can get Highest number of alarms at Alrm_code level to work properly - it needs to only apply to a specific alarm code, and not increase when another alarm is introduced to the data set. I just can't figure out how to do that!

Anonymous
Not applicable

I can't figure out how to make permission public. Is there any chance you can email me at pozzyal@gmail dot com to request permission? Someone else above did that and it worked, and I thought they had it working, but now that I play with bigger data sets, that doesn't seem to be the case, so I'm still trying to figure it out.

 

Or is there a better way to get you the data file?

 

thanks!

Alex

Anonymous
Not applicable

Wow! This is fantastic, thank you so much!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
itsmebvk
Continued Contributor
Continued Contributor


@Anonymous

 

Here 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"<=2

5) 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.

 

Output.PNG

 

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.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors