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

Modifying DAX Query for Large Dataset in Power Automate "Run a Query against a Dataset"

I have created a table chart using a field parameter with more than 1000 rows in Power BI. In Power Automate, I am using the "Run a Query against a Dataset" action, and I require assistance in modifying the DAX query.
 
Current DAX Query:
-----------------------------------------------------------------------------------
// DAX Query
DEFINE
VAR __DS0Core = 
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL(
ROLLUPGROUP(
Table_Name[PolicyTypeCode],
Table_Name[Channel],
Table_Name[Executive Code],
Table_Name[Executive Name],
Table_Name[BrokerExecCode],
Table_Name[BrokerExectiveName],
'GIM_Branch'[Branch Name],
Table_Name[Motor & Non Motor],
Table_Name[PolicyTypeDesc],
'Vehicle_Info'[PrdClassCode],
'Vehicle_Info'[PrdClassDesc]
), "IsGrandTotalRowTotal"
),
"count_NOP", Table_Name[count NOP],
"Countpkpoliid", IGNORE(
CALCULATE(COUNTA(Table_Name[pkpoliid]))
)
)
 
VAR __DS0PrimaryWindowed = 
TOPN(
502,
__DS0Core,
[IsGrandTotalRowTotal],
0,
Table_Name[PolicyTypeCode],
1,
Table_Name[Channel],
1,
Table_Name[Executive Code],
1,
Table_Name[Executive Name],
1,
Table_Name[BrokerExecCode],
1,
Table_Name[BrokerExectiveName],
1,
'GIM_Branch'[Branch Name],
1,
Table_Name[Motor & Non Motor],
1,
Table_Name[PolicyTypeDesc],
1,
'Vehicle_Info'[PrdClassCode],
1,
'Vehicle_Info'[PrdClassDesc],
1
)
 
VAR __DS0CoreNoInstanceFiltersNoTotals = 
FILTER(KEEPFILTERS(__DS0Core), [IsGrandTotalRowTotal] = FALSE)
 
EVALUATE
GROUPBY(
__DS0CoreNoInstanceFiltersNoTotals,
"Mincount_NOP", MINX(CURRENTGROUP(), [count_NOP]),
"Maxcount_NOP", MAXX(CURRENTGROUP(), [count_NOP]),
"MinCountpkpoliid", MINX(CURRENTGROUP(), [Countpkpoliid]),
"MaxCountpkpoliid", MAXX(CURRENTGROUP(), [Countpkpoliid])
)
 
EVALUATE
__DS0PrimaryWindowed
 
ORDER BY
[IsGrandTotalRowTotal] DESC,
Table_Name[PolicyTypeCode],
Table_Name[Channel],
Table_Name[Executive Code],
Table_Name[Executive Name],
Table_Name[BrokerExecCode],
Table_Name[BrokerExectiveName],
'GIM_Branch'[Branch Name],
Table_Name[Motor & Non Motor],
Table_Name[PolicyTypeDesc],
'Vehicle_Info'[PrdClassCode],
'Vehicle_Info'[PrdClassDesc]
 
 
// DAX Query 
DEFINE
VAR __DS0Core = 
SUMMARIZE(
'FIELD_PARAMETER',
'FIELD_PARAMETER'[FIELD_PARAMETER Fields],
'FIELD_PARAMETER'[FIELD_PARAMETER Order],
'FIELD_PARAMETER'[FIELD_PARAMETER]
)
 
VAR __DS0BodyLimited = 
TOPN(
152,
__DS0Core,
'FIELD_PARAMETER'[FIELD_PARAMETER Order],
1,
'FIELD_PARAMETER'[FIELD_PARAMETER Fields],
1,
'FIELD_PARAMETER'[FIELD_PARAMETER],
1
)
 
EVALUATE
__DS0BodyLimited
 
ORDER BY
'FIELD_PARAMETER'[FIELD_PARAMETER Order],
'FIELD_PARAMETER'[FIELD_PARAMETER Fields],
'FIELD_PARAMETER'[FIELD_PARAMETER]
-----------------------------------------------------------------------------------
 
I am seeking guidance on how to optimize this query to handle large datasets efficiently and improve performance.
 
Any suggestions or insights would be greatly appreciated.
 
Thank you for your assistance!

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Use a Table visual in Power BI to collect the columns and measures you need, with the required filters applied.  Disable Row Totals. Then grab the resulting DAX - you will see that it is much simpler.  Finally remove the TOPN limiter.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Use a Table visual in Power BI to collect the columns and measures you need, with the required filters applied.  Disable Row Totals. Then grab the resulting DAX - you will see that it is much simpler.  Finally remove the TOPN limiter.

A follow question if you don't mind, what is the row limit for that operation?  How many rows can be returned through Power Automate?

As far as I remember it is a payload size limit (rows times columns, up to 100 MiB), not a row limit. Use chunking/paging.

Hi @lbendlin,

Your insights were incredibly helpful and allowed me to overcome the challenge I was facing.

Thank you for taking the time to share your expertise with the community.
Your contributions are truly valued and make a difference.

Best regards,
jackson
Let's connect linkedin : )
https://linkedin.com/in/jackson-s-652396240

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.