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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Creating a Summarized Table by Top N

Hi,

 

I'm trying to create a summarized table filtered on the top (most recent) 12 months in the original table.  It would need to be filtered/summarized by the "year_period" field which is in a format like "202111" shown below.

 

jmays86_0-1639156795025.png

 

Any help accomplishing this would be much appreciated.  Thanks!

 

Jordan

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

I create a sample to show you how to create a summarized TopN month table by Dax.

2.png

Try this code to create a calcualted table.

 

Summarized Table by Top N =
VAR _N = 12
VAR _SUMMARIZED =
    SUMMARIZE ( 'Table', 'Table'[year_period] )
VAR _ADDRANK =
    ADDCOLUMNS ( _SUMMARIZED, "RANK", RANKX ( _SUMMARIZED, [year_period],, DESC ) )
VAR _TopN =
    SUMMARIZE ( FILTER ( _ADDRANK, [RANK] <= _N ), [year_period] )
RETURN
    _TopN

 

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous ,

 

Create a new column in the table

Year month = format([Date], "YYYYMM")

 

Create a new table

summarize(Table, Table[Month Year], "Measure", sum(Table[Value] ) )

 

 

Add other per need

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks @amitchandak  but I'm not sure how this would summarize the new table by Top 12 months in original table?

 

 

Anonymous
Not applicable

Hi @Anonymous ,

I create a sample to show you how to create a summarized TopN month table by Dax.

2.png

Try this code to create a calcualted table.

 

Summarized Table by Top N =
VAR _N = 12
VAR _SUMMARIZED =
    SUMMARIZE ( 'Table', 'Table'[year_period] )
VAR _ADDRANK =
    ADDCOLUMNS ( _SUMMARIZED, "RANK", RANKX ( _SUMMARIZED, [year_period],, DESC ) )
VAR _TopN =
    SUMMARIZE ( FILTER ( _ADDRANK, [RANK] <= _N ), [year_period] )
RETURN
    _TopN

 

Result is as below.

1.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.