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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
itsmeanuj
Helper IV
Helper IV

Toggle columns to be group by

Hi, I have a dataset of customers by product where PROD_CD is a subset of POD_GRP. Below is the sample.

 

Input  Data

CustomerPROD_CDPROD_GRPMonth1Month2Month3
A1Product1.AProduct1541821
A1Product1.BProduct11057

 

I want to create a table visual with the toggle (slicer or anything else) option to switch between the columns on which Monthly sales can be grouped by. Here is the example of the output view.

 

Output table view (Toggle 1)

CustomerProductMonth1Month2Month3
A1Product1.A541821
A1Product1.B1057

 

Output table view (Toggle 2)

CustomerProductMonth1Month2Month3
A1Product1642328
1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @itsmeanuj ,

 

In Query Editor mode, choose columns [PROD_CD] and [PROD_GRP], click "unpivot columns".

1.PNG

 

Rename columns.

2.PNG

 

Save above changes. In report view, drag [Slicer Items] into slicer and other fields into table visual.

3.PNG4.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @itsmeanuj ,

 

In Query Editor mode, choose columns [PROD_CD] and [PROD_GRP], click "unpivot columns".

1.PNG

 

Rename columns.

2.PNG

 

Save above changes. In report view, drag [Slicer Items] into slicer and other fields into table visual.

3.PNG4.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PattemManohar
Community Champion
Community Champion

@itsmeanuj  Please try this as a New Table

Test233Out = 
VAR _GroupByProdCD = SUMMARIZE(Test233Grouping,Test233Grouping[Customer],Test233Grouping[PROD_CD],"Month1",SUM(Test233Grouping[Month1]),"Month2",SUM(Test233Grouping[Month2]),"Month3",SUM(Test233Grouping[Month3]),"Type","Product Code")
VAR _GroupByProdGRP = SUMMARIZE(Test233Grouping,Test233Grouping[Customer],Test233Grouping[PROD_GRP],"Month1",SUM(Test233Grouping[Month1]),"Month2",SUM(Test233Grouping[Month2]),"Month3",SUM(Test233Grouping[Month3]),"Type","Product Group")
RETURN UNION(_GroupByProdGRP,_GroupByProdCD)

Then use the Type Field in the above table as Filter and remaining fields in the table visual.

 

image.pngimage.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Hi @PattemManohar - thanks for your response on this. So the situation is that there are 12 months field which keeps on changing every month with new month coming in. With this appraoch i will have to update the formula every month. Do you know how come we overcome this situation.

@agoyal Then in that case, you need to few more steps before creating a new table in DAX as below

 

In Power Query Editor, Unpivot all the columns other than the Month Fields using "Unpivot other Columns"

 

image.png

 

Then remaining steps are almost same as before, create a new table using DAX as below

 

Test233Out2 = 
VAR _GroupByProdCD = SUMMARIZE(Test233Grouping2,Test233Grouping2[Customer],Test233Grouping2[Month],Test233Grouping2[PROD_CD],"Value",SUM(Test233Grouping2[Value]),"Type","Product Code")
VAR _GroupByProdGRP = SUMMARIZE(Test233Grouping2,Test233Grouping2[Customer],Test233Grouping2[Month],Test233Grouping[PROD_GRP],"Value",SUM(Test233Grouping2[Value]),"Type","Product Group")
RETURN UNION(_GroupByProdGRP,_GroupByProdCD)

image.png

 

Now you need to use the Matrix visual instead of Table because we have data in row format and needs to be pivoted output. I've shown below both Matrix and Table visual outputs

 

image.pngimage.png

 

Please Note - "Unpivot Other Columns" is the key here, if you add Month4 to your sample data (which I've tested already as shown above) it will automatically pickup without any changes to your code.





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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