Renaming a file using a conditional statement - rename

How to rename file names using if condition?
I have many files on my computer and would like to change its names so that it would be more meaningful for me. The filenames are in the following format: cvcvcv198307.xlsx
I want to change it in such a way that
cvcvcv into Domain
1983 want to keep it
07 into 3-1 * And here is my main problem (Explanation below).
Each month (01-12) is divided into three data points. Meaning,
01(Jan) has three data points: 1,2, and 3
02(Feb) has the next three data points: 4,5, and 6
.
.
.
12(Dec) will have: 34,35, and 36
So, 01 in my original data means, first month, first data point, i.e. 1-1
02 - First month, and second data point, i.e. 1-2
03 - First month, third data point, i.e 1-3
04- second month, first data point, i.e. 2-1
05- 2-2
06- 2-3
07 - 3-1
08 - 3-2
09 - 3-3
10 - 4-1
11 - 4-2
12 - 4-3
.
.
.
35 - 12-2
36 - 12-3
And that's all.
I have tried file.rename along with sapply for my whole sets of data
(1:18,000). But i can only manage to change the file names before the last two #digits.
Expected result.
The whole file names changed from
cvcvcv198307.xlsx
cvcvcv198414.xlsx
into
Domain1983-3-1.txt
Domain1984-5-2.txt
(Yes, file name extension too!)

Related

Is there a way to filter information from a view and display them in the same view?

two months ago i asked this Question: How do i write more complex code in Lotus Notes views.
My View now looks like this:
Year
Month
Device
Counter
Times(Minutes)
Times(Hours)
2021
January
Test 01
270
4,5
Test 02
210
3,5
Test 01
60
1
Test 01
90
1,5
February
Test 01
30
0,5
Test 02
180
3
Test 01
60
1
The Database sets a new Document every time a Device is lend out. What i want to do now is to read trough every document and combine "Times(Minutes)" and "Times(Hours)" inside an variable, and also save each device name one time.When a device name is scanned more then once, the counter will go up by one. In my Lotus script program i did this using a Multi-Dimensional Array.
I Want to do this because i want to display each Device only One Time. Then each device has the combined values inside the "Times" Columns, and a counter to show how often the Device has been lend out in the chosen month. It should look like this:
Year
Month
Device
Counter
Times(Minutes)
Times(Hours)
2021
January
Test 01
3
420
7
Test 02
1
210
3,5
Feburary
Test 01
2
90
1,5
Test 02
1
180
3
If you set the device column to be categorised, and set totals on the Times columns properties, this will give you what you want. It will have the benefit that you can also see the total times across the month for all devices before you drill down

Retrieve range of data based on weeknumber

I'm setting up a database containing information of production runs. Each production run usually takes place within 24 h, leading to about 7 runs/week. Multiple values and variables are entered into the database, giving an idea how well/poorly each run went. I want to visualize this information in graphs, which give a weekly view (so 7 runs in 1 graph). My idea was to have a 2nd worksheet where I can input a week number, having Excel then show all runs (and all their relevant info) that took place in that week. This set area could then be used to fetch info for the graphs from. Idea being, I input a different week number, the values in this area change based on the runs for the new week and the graph looking at this are will automatically update.
I've been working with HLOOKUP based on dates, which works fine if 1 run takes place on 1 day.
Example: =HLOOKUP(D$2,'Run Values'!$C$6:$XFD$54,3,TRUE), where D$2is the date on which the run took place, 'Run Values!$C$6:$XFD$54 is the range where the values for each run can be stored (2nd worksheet), & 3 is the row for this particular piece of info (this value changes per row that I use the HLOOKUP in, depending on what I'm looking for).
However, when for some reason multiple runs took place on the same date (which occasionally happens), it only retrieves the first run encountered for that run. This is probably because I'm checking per date.
Is there a way to either improve this code (using HLOOKUP) to get it to do what I want it to do? Or is there an alternative (maybe more easy) way to get to where I want to be?
Sample data consists of weeks placed next to each other (1 week of data here):
43
43
43
43
43
25/10/2021
26/10/2021
26/10/2021
27/10/2021
28/10/2021
659
660
660
661
662
879
880PUR
881
882
883
34157
23034
27224
41740
40062
29.06%
29.75%
28.29%
27.51%
26.57%
12.58
9.65
9.65
14.20
16.17
I'm looking to extract the 1st through 4th row of the green values, 2nd through 9th row of the blue values, all of the light orange and all of the dark orange values for an entire week, and all this for 1 week of data at a time. So if I would request week 43 on my second worksheet, then it would retrieve them from this data base as such:
Any help would be much appreciated.

Distribute value equally over weeks by start- and end-date

I want to distribute a certain value (D4:D6) equally over the week-numbers (E3:J3) by its start- and end-date (B4:C6), as shown in the example.
A formula/vba script should do the following things:
Check which week-number the start- and end-date has
Divide the value by the amount of weeks between start- and end-date
Place the values in the matching column in the same row
The example in text format to copy:
2017 2018
Start End Value 50 51 52 1 2 3
26.12.2017 04.01.2018 20 - - 10 10 - -
12.12.2017 24.12.2017 50 25 25 - - - -
11.12.2017 10.01.2018 60 12 12 12 12 12 -
Also glad about hints / ideas how single steps could be achieved.
Proof of Concept:
place the following formula in E4 and copy down and right
=IF(WEEKNUM($C4,21)-WEEKNUM($B4,21)<0,IF(OR(E$3>=WEEKNUM($B4,21),E$3<=WEEKNUM($C4,21)),$D4/IF(WEEKNUM($C4,21)-WEEKNUM($B4,21)<0,MAX(WEEKNUM(DATE(YEAR($B4),12,{28,29,30,31}),21))-WEEKNUM($B4,21)+WEEKNUM($C4,21)+1,WEEKNUM($C4,21)-WEEKNUM($B4,21)+1),0),IF(AND(E$3>=WEEKNUM($B4,21),E$3<=WEEKNUM($C4,21)),$D4/IF(WEEKNUM($C4,21)-WEEKNUM($B4,21)<0,MAX(WEEKNUM(DATE(YEAR($B4),12,{28,29,30,31}),21))-WEEKNUM($B4,21)+WEEKNUM($C4,21)+1,WEEKNUM($C4,21)-WEEKNUM($B4,21)+1),0))
Now this is a built up formula from multiple cells that I back substitute the formulas to wind up with the monstrosity above. The break down is as follows.
STEP 1
Find the start week number. Place the following in B8.
=WEEKNUM($B4,21)
STEP 2
Find the end week number. Place the following in C8.
=WEEKNUM($C4,21)
STEP 3
Determine the maximum number of weeks in a year. Thanks to Ron Rosenfeld for this formula. Place the following in D8.
=MAX(WEEKNUM(DATE(YEAR($B4),12,{28,29,30,31}),21))
STEP 4
Determine if the week is in the same year or the following year. Place the following in E8.
=C8-B8
STEP 5
Determine the number of weeks. Place the following in F8.
=IF(E8<0,D8-B8+C8+1,C8-B8+1)
STEP 6
Average the value for each week. Place the following in G8.
=D4/F8
STEP 7
Determine if the average value belongs to a date header or the value of 0 (if you want an actual dash and not just formatting 0 as a dash then change 0 to -. Place the following formula in H8.
=IF($E8<0,IF(OR(E$3>=$B8,E$3<=$C8),$G8,0),IF(AND(E$3>=$B8,E$3<=$C8),$G8,0))
Copy the H8 formula to the right and down as required.
Caveat: Will work for a 1 year spread in work weeks. I have serious doubts that it would work over multi year start and end week.
Layout of steps

sumif range and criteria switching

So I have a table of number of fiscal weeks in a year, and to calculate depreciation I'm trying to sum the number of weeks in the total life of the capital investment. So the first argument is the range, the second argument pulls the year from another cell, and then adds the expected life in years of the device. The third argument is the intended sum range.
SUMIF(YearWeeks[Year],"<="&LEFT(AS$14,4)+$H20,YearWeeks[Weeks])
This works fine. Pulls in the right numbers no problem.
However, whenever I try and drag this across other cells so that it can be used throughout my spreadsheet to caculate depreciation, it immediately switches the value for year and the value for weeks and becomes:
SUMIF(YearWeeks[Weeks],"<="&LEFT(AU$14,4)+$H20,YearWeeks[Year])
I cannot figure out why it is doing this. It is probably something simple, but it is completely evading me. Any help would be greatly appreciated.
Year Weeks
2015 52
2016 53
2017 52
2018 52
2019 52
2020 52
2021 53
2022 52
2023 52
2024 52
2025 52
2026 52
2027 53
2028 52
2029 52
2030 52
Life
5
5
5
5
5
5
5
5
8
8
8
8
8
8
201504 201505 201506 201507 201508 201509 201510 201511 201512 201601 201602 201603
Instead of dragging the formula to the right, copy the cell and paste it in the cell at the right of it, etc... :
This will keep the column references unchanged (no change from YearWeeks[Weeks] to YearWeeks[Year]).
As specified on Microsoft's support website:
Moving, copying, and filling structured references
All structured references remain the same when you copy or move a formula that uses a structured reference.
When you fill a formula, fully qualified structured references can adjust the column specifiers like a series as summarized in the following table.
NB: YearWeeks[Weeks] is a structured reference, and fill is what many would call drag in this context.

Timestamps, majorating and sum

I'm with a problem doing a part of a program, I hope you can help me.
I have this three columns in excel;
01-01-2012 00:15 A 7,160000
01-01-2012 00:30 A 1,600000
01-01-2012 00:45 C 3,040000
01-01-2012 01:00 A 1,560000
01-01-2012 01:15 A 0,000000
01-01-2012 01:30 D 0,000000
01-01-2012 01:45 A 0,000000
t goes until 31-01-2012 23:45
And now I want to read them into MATLAB and convert them into 3 new matrix with this format;
Timestamp
01-01-2012 00:00
01-01-2012 01:00
(...)
Period
A
A
Price
11,800000
10
So basically I want a program that read's timestamp and keep's day month year and hour (ignoring the minutes), for that period of time it needs to show the most repetitive value in periods of one hour (for example: it will give A to 00 and C to 01) and finally I want it to sum the prices for that hour (so it will sum the price at 00:15 + price at 00:30 etc.)
It will be a huge help, if you can solve me this problem.
P.S In the 1 hour periods I will always have one most repetitive marker (3 of A and 1 C, 3 D and 1 A etc.) I could find in this month 4 markers, A B C D. This markers aren't cyclic but I will find it all across the month.
It seems to me like your main issue is reading the data from Excel and get it in a format you can work with. If so:
Check out xlsread. You have a lot of possibilities there. You can for instance use the following syntax:
[num,txt,raw] = xlsread(___)
but if you are new to MATLAB and don't require the most efficient way, I would recommend you to read each of the columns separately. Note: This is not the best way, but it's the easiest way in my opinion. You can use this command on each of the columns (thus calling it three times):
num = xlsread(filename,sheet,xlRange)
Check out this page to see how you can handle the dates. In summary, convert the dates to numeric values in Excel. Since you have hours and minutes, this will be a decimal number representing the number of days since Jan 01, 1900 (or Jan 02, 1904 if on MAC). Since MATLAB counts from Jan 01, 0000, you need to add some 1900 years after reading the file (check the reference I gave to see how).
One way to handle that you don't want minutes is to convert to datevec, and zero out the last columns (this way you will also remove the information):
[Y, M, D, H, MN, S] = datevec(___) ;
% or
date_vector = datevec(___);
% Where you just don't use the MN and S variables
If you want the dates looking like dates, convert the datevec to datestring. Check out formatOut, and you can choose the format you want.
Try out the above. I'm afraid I can't do that work for you.
To get the most repetitive values, check out mode. mode(X) returns the sample mode of X, which is the most frequently occurring value in X. You can also replicate this functionality by combining some of the following: sort, unique, diff or all. And you can of course use sum to sum the values.
If it's only the last part here your stuck on, I suggest you rephrase the question a bit. If it's both, and you get stuck on the last part after doing the above, I suggest you ask it as a separate question, as that won't be related to reading it from Excel.
Good luck =)

Resources