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

Is it possible to group columns together, and then filter by group?

Hello All.

 

First off, I am new to power BI, so please bear with me (I am hoping I have included all necessary information).

 

I have searched to see if there were previous questions asked that are similar to my question but looking at other solutions, these solutions did not seem to fit exactly what I was looking for.

 

The sample data I am working with is classes, and number of students who attended those classes, and dates attended(screenshot below).

 

attendance table.PNG

 

I was wondering if it was possible to group classes together, and then use the group as a slicer.

 

For example lets say class1 & class2 are math classes,  class3 and class4 are history classes, class5 and class6 are science classes.

 

I would then like to have a filter/slicer with options of math, history, science, so when when I select math, only class1 and class2 data are shown.

 

I am not sure if what I am wanting to do is possible.

 

 

Any help is appreciated.

 

Thank you in advance. 

 

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

Click on Edit Queries and right click on the first column > Unpivot Other columns.  Click on Add Column > Custom column and write this M formula there

 

=if [Attribute]="class1" or [Attribute]="class2" then "Maths Classes" else if [Attribute]="class3" or [Attribute]="class4" then "History Classes" else "Science classes"

 

Alternatively, after unpivoting, click on Close and Load.  Then go to Data Modelling and write this calculated column formula

 

=IF(OR([Attribute]="Class1",[Attribute]="Class2"),"Maths Classes",IF(OR([Attribute]="Class3",[Attribute]="Class4"),"History Classes","Science Classes"))

 

Hope this helps.


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

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

 

Click on Edit Queries and right click on the first column > Unpivot Other columns.  Click on Add Column > Custom column and write this M formula there

 

=if [Attribute]="class1" or [Attribute]="class2" then "Maths Classes" else if [Attribute]="class3" or [Attribute]="class4" then "History Classes" else "Science classes"

 

Alternatively, after unpivoting, click on Close and Load.  Then go to Data Modelling and write this calculated column formula

 

=IF(OR([Attribute]="Class1",[Attribute]="Class2"),"Maths Classes",IF(OR([Attribute]="Class3",[Attribute]="Class4"),"History Classes","Science Classes"))

 

Hope this helps.


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

THANK YOU THANK YOU THANK YOU!

 

This was exactly what I was looking for.

 

I appreciate your help and walking me through this. 

You are welcome.


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

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.