Are you going to show us how o setup a daily data refresh for the Cost Management export?
Yes but first of all I need to show you something and you tell me if you see anything wrong:
Well, the daily export is missing.
That’s right. This is how they do it at Microsoft; because they cannot really calculate your daily consumption each day (which it’s already odd by itself) they propose you:
- Daily export of month-to-date costs: II don’t know for what reason but Microsoft cannot calculate how much you spent yesterday. That’s why they don’t propose a daily export but a month-to-date export. This way you are forced to substitute that file every day and their miscalculation are corrected.
- Weekly export of last 7 days: never tried yet, put a comment if you know how it behaves
- Monthly export of last month’s costs: Each monthly export will be executed on the 5th of every month. This means that Microsoft is giving us an hint about how many days they need to calculate it right, 5 days.
- One-time export: use it carefully, now that you know that you don’t have that precision in the last 5 days
So what we are going to do now is setting up a Logic App that will substitute the month-to-date export daily.
And are you going to give us the step by step roadmap with pictures?
Open your mouth, the airplane is coming… here the first step:
1) Recurrence
Setup a regular Recurrence with 1 hour interval. You cannot really tell at what time Microsoft is going to drop that file:
2) List blobs (V2)
Use List blob (V2) to target a valid Storage account and a container:
3) Initialize Variable
We create a variable with function utcNow()
:
4) Initialize Variable 2
And another variable in which we are going to use the function
concat(split(variables('CurrentDate'),'-')[0],split(variables('CurrentDate'),'-')[1])
:
5) For each
OK, this step is much more complicated that you think, it looks like this:
I’m going to brake it down in small chunks so you don’t get mad. The very first step says check if there is a folder and if its name starts with a date:
If that is the case take the name of that folder, which is our input folder, navigate to it, and enumerate if there are files in it
And now go into the LatestCSV folder, which is our output folder, and see if there are files into it
And is the folder LatestCSV empty? No? Well, that’s alright, in fact is containing yesterday’s month-to-date CSV Export. So go into that folder and delete that file:
And now go to the input folder where the CSV are exported, copy that CSV to the LatestCSV folder, and after that you have moved the file delete the folder that was containing it:
That wasn’t easy.
Yeah, I know.
It’s a pity that Microsoft hasn’t put in place an auto month-to-date cancelling.
In fact it would be that easy: because the Storage account cannot contain files with the same name they should have named the month-to-date export always with the same name.
This way the month-to-date export would have automatically replaced the previous one.
But why doing easy things when you can do hard ones?