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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
bajimmy1983
Helper V
Helper V

try statement with Folder.Files

Hi Community.

 

I have 3 different sources in order to import all files using Folder.Files importation option...

 

SourceA = ...

SourceB = ...

SourceC = ...

 

To do so, I am trying to apply "try ... otherwise" in Folder.Files same as I did with Excel.Workbook, but it seems with Folder.FIles it is not working same way. 

 

I tried at least 2 Scripts, but both failed to find my network path which is SourceC. If I transfer F:\Pilot\Pilot_Bases_Actual_Year to SourceA, then it works. So I am assuming try stetament is not going down to SourceB and SourceC as expected. Can anyone help me understand why and how to fix it? 

 

Script 1

 

SourceA = try Folder.Files("C:\Users\jaderson.almeida\Havas\OneDrive - Havas\Pipeline 2017\SupportTables\Pilot_Bases_Actual_Year"), 
SourceB = try Folder.Files("G:\FINANCEIRO\MO Controller\Pilot\Pilot_Bases_Actual_Year"),
SourceC = try Folder.Files("F:\Pilot\Pilot_Bases_Actual_Year"),

DynamicSource = if SourceA[Value] is table then SourceA[Value] else 
                if SourceB[Value] is table then SourceB[Value] else 
                if SourceC[Value] is table then SourceC[Value] else null,

    Source = DynamicSource,

Rest of script

 

Script 2

 

SourceA = Folder.Files("C:\Users\jaderson.almeida\Havas\OneDrive - Havas\Pipeline 2017\SupportTables\Pilot_Bases_Actual_Year"),
SourceB = Folder.Files("G:\FINANCEIRO\MO Controller\Pilot\Pilot_Bases_Actual_Year"), 
SourceC = Folder.Files("F:\Pilot\Pilot_Bases_Actual_Year"),

DynamicSource = try SourceA otherwise 
                try SourceB otherwise
                try SourceC otherwise null,

    Source = DynamicSource,

Rest of script

 

Thanks in advance again,

Jimmy

Jaderson Almeida
Business Coordinator
3 REPLIES 3
v-jiascu-msft
Employee
Employee

Hi @bajimmy1983,

 

Could you please mark the proper answer as solution?

 

Best Regards!
Dale

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

Hello @v-jiascu-msft. Sorry to delay my reply. I am on vacation with very limited email access. 

 

So, I tried your suggestion, but no way, it failed. 

 

Yes, same construction steps.

Jaderson Almeida
Business Coordinator
v-jiascu-msft
Employee
Employee

Hi Jimmy,

 

 

Since it's a network folder, maybe you can try it out like this: \\computer name\folder path.

SourceC = try Folder.Files("\\Pilot\Pilot_Bases_Actual_Year"),

I have to ask if all the files have the same structures. Or the following steps will be broken if the data source switches among the three sources.

 

Best Regards,

Dale

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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