Skip to main content

Notifications

Community site session details

Community site session details

Session Id : HzRVyDJFgb37u7kSjzzHHW
Power Automate - Building Flows
Answered

Power Automate running a DAX query but creating a CSV with different sorting from original Power BI query

Like (0) ShareShare
ReportReport
Posted on 27 Jun 2023 14:08:42 by 36

I created the following 'Run a query against a dataset' instant cloud flow, where the output from such DAX query is transferred over to a CSV table, which is saved to a Sharepoint folder, and then the flow continues on until the contents of such CSV is parsed onto a Sharepoint list.

 

Fat_CC_Lancamentos_Orig_CSV_Sharepoint.png

 

The flow is running fine, until I realized that after making a columns sorting criteria change to the data table in Power Query, the flow still produces a CSV with the same sorting criteria prior to those changes I had just made, as if it's "stuck in time" somehow.

 

To illustrate what I mean, I've put together a print where the left hand side brings the query directly out of a Power BI table (thus capturing the aforementioned changes in sorting criteria), and then after extracting the DAX code via Performance Analyzer and pasting onto the flow, I pasted the CSV resulted from such flow to the right hand side of the print (please note the query has an index column 'ID_Lanc', and the sorting criteria is performed before the insertion of such index column, which locks the order of sorting into place).

 

Fat_CC_Lancamentos_Orig_SxS.png

 

I even created a brand new flow after I changed the data table's sorting criteria in Power Query and saved the resulting CSV on a OneDrive folder, but the result produced is still the same: stuck in the old sorting criteria.

 

Fat_CC_Lancamentos_Orig_CSV_OneDrive.png

 

Upon investigation I'm pretty sure the culprit resides under the 'Run a query against a dataset' step, I just couldn't pinpoint exactly where by looking at the JSON code that comes out of it since I'm a newbie on all this.

 

Below is the DAX code placed under 'Run a query against a dataset'. I also tried running a simpler version of the code by getting rid of the '__DS0PrimaryWindowed'/TOPN piece and running only the '__DS0Core'/SUMMARIZE part of the code, and I also tried swapping SUMMARIZE with SUMMARIZECOLUMNS, but yet I keep getting the same CSV output with wrong (old) sorting criteria:

 

DEFINE
	VAR __DS0Core = 
		SUMMARIZE(
			'Fat_CC_Lancamentos_Orig',
			'Fat_CC_Lancamentos_Orig'[ID_Lanc],
			'Fat_CC_Lancamentos_Orig'[Banco/CartĂŁo],
			'Fat_CC_Lancamentos_Orig'[Data Vencimento Fatura],
			'Fat_CC_Lancamentos_Orig'[Data],
			'Fat_CC_Lancamentos_Orig'[Descrição],
			'Fat_CC_Lancamentos_Orig'[Lançamento]
		)

	VAR __DS0PrimaryWindowed = 
		TOPN(
			100000,
			__DS0Core,
			'Fat_CC_Lancamentos_Orig'[ID_Lanc],
			1,
			'Fat_CC_Lancamentos_Orig'[Banco/CartĂŁo],
			1,
			'Fat_CC_Lancamentos_Orig'[Data Vencimento Fatura],
			1,
			'Fat_CC_Lancamentos_Orig'[Data],
			1,
			'Fat_CC_Lancamentos_Orig'[Descrição],
			1,
			'Fat_CC_Lancamentos_Orig'[Lançamento],
			1
		)

EVALUATE
	__DS0PrimaryWindowed

ORDER BY
	'Fat_CC_Lancamentos_Orig'[ID_Lanc],
	'Fat_CC_Lancamentos_Orig'[Banco/CartĂŁo],
	'Fat_CC_Lancamentos_Orig'[Data Vencimento Fatura],
	'Fat_CC_Lancamentos_Orig'[Data],
	'Fat_CC_Lancamentos_Orig'[Descrição],
	'Fat_CC_Lancamentos_Orig'[Lançamento]

 

I really ran out of ways of trying to solve this issue, any help on this one would be greatly appreciated!

  • Verified answer
    leolapa_acumen Profile Picture
    36 on 28 Jun 2023 at 22:04:21
    Re: Power Automate running a DAX query but creating a CSV with different sorting from original Power BI query

    The issue on the following link presented a somewhat similar situation:

     

    https://powerusers.microsoft.com/t5/Building-Flows/Power-BI-run-a-query-against-a-dataset-struggling-with-DAX-query/td-p/2047914 

     

    The user there realized he switched Power BI users on the dataset and that's what was causing this problem on this query always getting an outdated version. 

     

    I then remembered that I also had switched users on my dataset, so I replicated the same dataset from scratch on a brand new dataset under the new user, and now the CSV presents a current version of the DAX query.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard