I have uploaded the below excel in sharepoint document library in order to power automate to create folder structure
Please note i need to create above excel details in the nested folder into my sharepoint document library
Flow steps
Expanding Applyto each step
Expanding Apply to each step
Hi @Veblitz !
Please see below flow of mine. I replicated same and it works. I'll explain it on the way with every screenshot for you to understand.
Flow:
Pic 1
Pic 2
Pic 3
Let me explain now:
I guess till list rows is already understood.
I added these two actions because of the case where you have all columns empty in a row based on your data from excel:
This will help to filter the rows based on an expression:
@or(not(equals(trim(item()?['Month']), '')), not(equals(trim(item()?['Country']), '')), not(equals(trim(item()?['Customer']), '')), not(equals(trim(item()?['New']), '')))
Please ignore the warning above this action after inserting this action and going back to basic mode. It will work for sure.
So example output will be for this:
And its just what you need. Use this body in the output of apply to each action.
The condition 5 (change the name as you want. I just kept it as the same) is really important. This is the year folder.
2024
│
├── 1
│ └── USA
│ └── Microsoft
│ └── Renewal
│
├── 2
│ └── UK
│ └── ABC
│ └── Pending
│
└── 3
└── [Country Not Specified]
└── Cool
└── Approvals
You gave me this right? Now see in the case of this:
└── 3
└── [Country Not Specified]
└── Cool
└── Approvals
You know based on above, the year folder serves as a parent folder to the rest as the year column for the other two rows are empty. This is what the condition does. Store this year folder name in a variable and use it throughout till it encounters another year in that column of which it will overwrite the previous year.
Now I will give expressions for each condition and its yes and no parts:
1) Condition 5
Expressions used:
(type these in the expression tab)
Condition 5:
not(equals(items('Apply_to_each')?['Year'],''))
true (type this in the expression tab)
directly paste the following in the "Folder Path" section:
Create new folder 5:
@{items('Apply_to_each')?['Year']}
2) Condition
Expressions used:
(type these in the expression tab)
Condition:
not(empty(items('Apply_to_each')?['Month']))
true (type this in the expression tab)
directly paste the following in the "Folder Path" section:
Create new folder 4:
@{variables('Year')}/@{items('Apply_to_each')?['Month']}
3) Condition 2
Expressions used:
(type these in the expression tab)
Condition 2:
not(empty(items('Apply_to_each')?['Country']))
true (type this in the expression tab)
directly paste the following in the "Folder Path" section:
Create new folder 3:
@{variables('Year')}/@{items('Apply_to_each')?['Month']}/@{items('Apply_to_each')?['Country']}
4) Condition 3
Expressions used:
(type these in the expression tab)
Condition 3:
not(empty(items('Apply_to_each')?['Customer']))
true (type this in the expression tab)
directly paste the following in the "Folder Path" section:
Create new folder 2:
@{variables('Year')}/@{items('Apply_to_each')?['Month']}/@{items('Apply_to_each')?['Country']}/@{items('Apply_to_each')?['Customer']}
5) Condition 4
Expressions used:
(type these in the expression tab)
Condition 4:
not(empty(items('Apply_to_each')?['New']))
true (type this in the expression tab)
directly paste the following in the "Folder Path" section:
Create new folder:
@{variables('Year')}/@{items('Apply_to_each')?['Month']}/@{items('Apply_to_each')?['Country']}/@{items('Apply_to_each')?['Customer']}/@{items('Apply_to_each')?['Name']}
Input:
Output:
In 2022:
In 2023:
The other one of 2023 has Month column empty hence won't create the folders for the subsequent data.
In 2024:
This flow will surely guarantee you 100% success in creating the folders.
I hope this helps. Please do let me know once tried.
Yes correct.
I just removed apply to each and with one loop i managed to create nested folders and it looks alright but not sure if work for more sub folders .
Thanks for your continuous inputs and it helped me to learn issues and able to resolve errors
My excel values are
Document library nested folder structure once flow ran output
when i click 2022 folder
when i click 2022/1 folder level
when i click 2022/1/uk folder level
Overall, if you see the excel values and the below one we are not sure y 1,2,3 month is getting created for the year 2022,2023,2024 since we don't have 3 subfolders in the each year
Yes i removed blank values but unfortunately we are able to get rid of error but folder structure is not getting created as expected.I am unable to create remaining 2 levels but no error and this time no blank spaces
Thanks.
It's creating year and month nested folders though if it's having blank spaces and after which it's getting failed
encodeUriComponent(concat(outputs('Create_new_folder')?['body/Title'],'/',items('Apply_to_each2')))
Im getting error details as "path for the new folder is not provided"
Thanks for the inputs
I am able to create two levels such as year and month (2 levels) and the remaining levels were not getting created hence im getting such errors.
Im not sure how to reference EncodeURIComponent() function with the above usecase.
encodeUriComponent(variables('Uri'))// what value we may need to reference