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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

Logic Within "Get Data"

Is it possible to setup logic within the "Get Data" Source? I am looking to see whether or not there is data at the source, and if not, then it will setup a table with no data. If there is data, it will pull the data and transform as I desire.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You can add the following code to the M of the data source, below is my example using Excel as the data source.

 

Rows = Table.RowCount(#"Promoted Headers"),
Table = if Rows > 0 then #"Promoted Headers" else Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t])

vkkfmsft_0-1642050751936.png

 

1. When the data in the excel is empty, display the custom data.

 

vkkfmsft_1-1642050792832.png

 

2. When the excel data is not empty, import it.

 

vkkfmsft_2-1642050839006.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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
bcdobbs
Super User
Super User

I started to reply to suggest you could use an if statement in advance editor to switch between two queries that aren't loaded (https://docs.microsoft.com/en-us/powerquery-m/m-spec-conditionals)

 

However am slightly confused, what is your source? Generally if a source returns no data you get an empty table anyway.

 

Are you trying to read from files that may or may not exist?



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

My source is a website that returns a DataSourcePath error, presumably meaning the website location does not currently exist. However, at certain times in the month, this website path does contain data uploaded and active. 

Hi @Anonymous ,

 

You can add the following code to the M of the data source, below is my example using Excel as the data source.

 

Rows = Table.RowCount(#"Promoted Headers"),
Table = if Rows > 0 then #"Promoted Headers" else Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t])

vkkfmsft_0-1642050751936.png

 

1. When the data in the excel is empty, display the custom data.

 

vkkfmsft_1-1642050792832.png

 

2. When the excel data is not empty, import it.

 

vkkfmsft_2-1642050839006.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.