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
lastnn30
Post Patron
Post Patron

help with answering this question for a dataset -Which injury location is the most common for each?

Hi

I have this dataset and I am trying to answer the following question without writing DAX? just create a visual with filter/silicer etc

 

Which injury location is the most common for each plant?

 

I solved it by creating matrix but it is not showing what is the most common injury. I have to find that manually. Please see the screenshot, I am also attaching the dataset.

 

SNAG-0592.jpg

This is the DataSet link

https://drive.google.com/file/d/1pOEqVBabfepk-BvxUT45S91VuHWDw4Fp/view?usp=sharing

 

 

4 ACCEPTED SOLUTIONS
tackytechtom
Super User
Super User

Hi @lastnn30 ,

 

Is there a special reason why you don't want to use DAX for this? 🙂 I would have created a measure to solve your issue, so let me know if you need some help with creating one. Otherwise, here a shot on how to solve it just visually:

 

Option 1

tomfox_1-1650048539823.pngOn the left, a slicer for plant which only allows single select. On the right, a table visual including color coding on the max of the count of incident type. 

 

Option 2

tomfox_2-1650049346648.png

 

Left, the slicer and on the right a table with a Top N (Top 1) filter by Count of Incident Type.

 

Was it kinda this what you meant?

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

tackytechtom
Super User
Super User

Hi @lastnn30 ,

 

I think, this is what you would like to achieve, isn't it?

tomfox_0-1650058441778.png

 

Here a little (or rather detailed) walkthrough on how I would do it:

1) create the count measure:

 

DAX:

MeasureCountIncidentType = 
COUNT ( SafetyData1[Incident Type] )

 

PBI:

tomfox_1-1650058649968.png

 

As you can see, the measure does the same as dragging in the column and then changing it to COUNT in the Values pane. Still, I would recommend to always create a dedicated measure instead of using the "drag in a column approach". Also, the measure returns the same result as using a COUNTROWS ( SafetyData1 ) since we are actually interested in how many incidents (= rows) occured. Anyway, we can keep this measure as it is for now since this was the one from the start.

 

2) create the actual measure showing which injury type appeared the most per plant.

 

Here the whole measure, but I will guide you through each of the parts:

MeasureMaxCountIncidentTypePerPlant = 
VAR _helpTable = 
SUMMARIZE ( 
    ALLEXCEPT ('SafetyData1', SafetyData1[Plant]), 
    'SafetyData1'[Injury Location], 
    "Measure", [MeasureCountIncidentType]
)
VAR _maxCount = 
CALCULATE ( 
    MAXX ( _helpTable, [Measure] )
)
RETURN
CALCULATE ( MAX ( 'SafetyData1'[Injury Location] ), FILTER ( _helpTable, [Measure] = _maxCount  ))

 

The _helpTable would look like this in PBI:

tomfox_2-1650060248805.png

 

It does the summarization on injury location and displays the overall count for each of them. 

 

Using _maxCount solely in PBI would obviosuly show the maximum of the table above:

tomfox_3-1650060478622.png

 

It gets interesting though when using the _maxCount together with the plant attribute because this filters the _helpTable and consequently shows the maximum count of injury location per plant:

tomfox_4-1650060779166.png

 

So we are almost there. All we need to do now is to look per plant which injury location matches the maximum count of injury location or in more simple words, what is the most frequent injury location per plant. That equals the last line of the measure.

 

Hope this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

Hi @lastnn30 ,

 

Here the settings for the background color conditional formatting:

tomfox_0-1650092040340.png

 

 

Do not forget to mark one or multiple answers as a solution so people have it easier to find it in the future. Also, @Ashish_Mathur 's solution is very neat! His approach returns even multiple incident types if there are more than one maximum!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

10 REPLIES 10
lastnn30
Post Patron
Post Patron

Many thanks Tom. I appreciate all the help. Thanks again.

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

Thank you very much Ashish for your help. I appreciate it.

You are welcome.


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

Hi @lastnn30 ,

 

I think, this is what you would like to achieve, isn't it?

tomfox_0-1650058441778.png

 

Here a little (or rather detailed) walkthrough on how I would do it:

1) create the count measure:

 

DAX:

MeasureCountIncidentType = 
COUNT ( SafetyData1[Incident Type] )

 

PBI:

tomfox_1-1650058649968.png

 

As you can see, the measure does the same as dragging in the column and then changing it to COUNT in the Values pane. Still, I would recommend to always create a dedicated measure instead of using the "drag in a column approach". Also, the measure returns the same result as using a COUNTROWS ( SafetyData1 ) since we are actually interested in how many incidents (= rows) occured. Anyway, we can keep this measure as it is for now since this was the one from the start.

 

2) create the actual measure showing which injury type appeared the most per plant.

 

Here the whole measure, but I will guide you through each of the parts:

MeasureMaxCountIncidentTypePerPlant = 
VAR _helpTable = 
SUMMARIZE ( 
    ALLEXCEPT ('SafetyData1', SafetyData1[Plant]), 
    'SafetyData1'[Injury Location], 
    "Measure", [MeasureCountIncidentType]
)
VAR _maxCount = 
CALCULATE ( 
    MAXX ( _helpTable, [Measure] )
)
RETURN
CALCULATE ( MAX ( 'SafetyData1'[Injury Location] ), FILTER ( _helpTable, [Measure] = _maxCount  ))

 

The _helpTable would look like this in PBI:

tomfox_2-1650060248805.png

 

It does the summarization on injury location and displays the overall count for each of them. 

 

Using _maxCount solely in PBI would obviosuly show the maximum of the table above:

tomfox_3-1650060478622.png

 

It gets interesting though when using the _maxCount together with the plant attribute because this filters the _helpTable and consequently shows the maximum count of injury location per plant:

tomfox_4-1650060779166.png

 

So we are almost there. All we need to do now is to look per plant which injury location matches the maximum count of injury location or in more simple words, what is the most frequent injury location per plant. That equals the last line of the measure.

 

Hope this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @lastnn30 ,

 

Is there a special reason why you don't want to use DAX for this? 🙂 I would have created a measure to solve your issue, so let me know if you need some help with creating one. Otherwise, here a shot on how to solve it just visually:

 

Option 1

tomfox_1-1650048539823.pngOn the left, a slicer for plant which only allows single select. On the right, a table visual including color coding on the max of the count of incident type. 

 

Option 2

tomfox_2-1650049346648.png

 

Left, the slicer and on the right a table with a Top N (Top 1) filter by Count of Incident Type.

 

Was it kinda this what you meant?

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thank you so much for the DAX. I will study it carfully. Can not thank you enough. Sorry for bothering you once again, about the color coding the max (without using DAX), how did you do that? I tried conditional formatting that column but I did not get the same result as yours? Thank you once again.

Hi @lastnn30 ,

 

Here the settings for the background color conditional formatting:

tomfox_0-1650092040340.png

 

 

Do not forget to mark one or multiple answers as a solution so people have it easier to find it in the future. Also, @Ashish_Mathur 's solution is very neat! His approach returns even multiple incident types if there are more than one maximum!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thank you for your kind words @tackytechtom


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

Thank you very much Tom for the help. The reason is that I am not familiar with DAX and now I am trying to understand it. So, if you do not mind, I would appreciate if you can show me the code (measure) so I can learn from it. I am trying to learn DAX by examples. Again thanks for you help. I appreciate it. Thanks

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.