Extracting information using regex - regex

I am new to SQL and need to query a database to extract certain information before I can import it into another software I am familiar with to analyse the data. The table I am trying to query has information that looks like below:
MV: Gone Girl (2014)
BT: USD 61,000,000
CP: Twentieth Century Fox Film Corporation, Regency Entertainment (USA), Inc.
GR: USD 167,735,396 (USA) (8 February 2015)
GR: USD 167,590,676 (USA) (25 January 2015)
GR: USD 37,513,109 (USA) (5 October 2014)
GR: USD 167,761,501 (USA)
I would like to extract the information in the lines that start with GR, and I would like to organize them into four columns;
currency,
amount,
country,
date.
After spending a lot of time I have now put together the following code (I know it is not an elegant way of doing it), but it does not grab the information in the last line because it is missing the date information. I would like the date column to be empty for the last row, but still extract all the other information.
regex_match '(?:GR:[ ]([A-Z]{3})[ ](\d{1,3}(?:[,]\d{3})+)[ ][(](USA)[)][ ][(](?:|\d{1,2}[ ]\w+[ ]\d{1,4})){1}','g')
I would be grateful if someone could help me to fix my code.

This might do what you want even if I'm not sure it's what you need it's at least what you asked :
(?:GR: )([A-Z]{3}) ((?:[0-9]{1,3},*)*) (?:\(([A-Z]{3})\)) *(?:\(([1-9]{1,2} [a-zA-Z]* [0-9]{4})\))*
You can check here to see the result.
You have 4 groups one for each of your column. And sometimes the fourth can be empty (if there is no date for example).

Related

Website automation regarding when to ship out live animals in respects to extreme temperatures

If someone could please advise on how to achieve the following function on my site: I have a business where I ship live animals to customers. The challenge is communicating the weather forecast with the customer, along with the safest day/s to ship for the animals’ wellbeing. This planning is especially key during the peak summer and winter months when temperatures are very extreme. I am looking to automate these functions during the customers checkout process, giving them control of the shipping date. I am looking to implement something like this on my site.
I found another website where I recently placed an order that provided this relevant information for the customer to review before deciding on what day they would like to have the animal shipment shipped out. The table provided a 5 day forecast, which included temperatures for morning and evening at the point of origin, in transit, as well as the customers’ destination address. Any day/s where the temperature is too hot or too cold was marked as unavailable (red) for shipping. Possible shipping dates consisted of two consecutive days where temps are in the safe range and labeled as available (green) Excluding Friday, Saturday, and Sunday. It is also important for the customer to plan ahead and pick a shipping day based on their availability to be home to receive the package the following morning.

Power Query - How to create a perpetual calendar with holidays

I would like to create a perpetual calendar in Power BI (Power Query) with the holidays. The thing is, I live in Canada and Easter and Victoria Day are quite complicated to integrate in this kind of calendar.
For the perpetual calendar, I used this technique (you can find the code on this website), which is very effective. It's "simply" a function to which you tell that you want a calendar from this date to this date and it generates everything you want and probably more. However, the calendar doesn't know which day is a holiday. So you need to have another request in Power BI with all the holidays for that period. Then you tell the calendar to use this holiday request as a reference point and then it will know which day is a holiday.
This is where it gets very complicated. Some holidays are based on a specific date, some are based on a specific day and others vary a lot.
Based on a specific date : New Year's Day, January 1st ; Saint-Jean-Baptiste Day, June 24 ; Canada Day, July 1st ; National Day for Thruth and Reconciliation, September 30 ; Remembrance Day, November 11 ; Christmas Day, December 25 ; Boxing Day, December 26.
Based on a specific day : Labour day, first Monday of September ; Thanksgiving, second Monday of October.
Those that vary a lot : Good Friday, Friday before Easter ; Easter, first Sunday after the Paschal full moon ; Easter Monday, Monday after Easter ; Victoria Day, last Monday preceding May 25.
Finally, some holidays happen only once to commemorate specific events like the death of the Queen on September 19, 2022.
I would like to create a function to which I indicate that I want all holiday for a specific period and it generates everything by itself. Then I could tell my calendar function to use it as a reference to know which day is a holiday. It would also be great if I could add some new holiday here and there for specific events like the death of the Queen.
For holidays like New Year's Day, Canada Day and Thanksgiving, I used this tutorial, but it's incomplete. Also, it doesn’t explain how to integrate holidays like Easter or Victoria Day. So this is where I'm stuck right now.
I know it's complicated but if someone can help me, it would be awesome.
As Jon suggest, I think it will be a lot easier to use the canada-holidays.ca/api.
I'm having issues with this API though. If I want multiple years in a single request, I need to create a request for each year and then append them. I'm trying to find a way to only have a single request but I'm struggling with this as well.
As soon as I find a solution, I'll update this post.
EDIT
Someone help me with that on another post. You can find the solution right here!

Using multiple IF/AND statements to look at a query table and display a Yes/No result

I'm attempting to write a formula for excel that will look at 3 different columns of data in a query table that I'm pulling from my teams sharepoint site. I'm trying to have a Yes/No result given.
The formula I've written so far is
=IF(AND(ISTEXT(Governance_Master_List__2[Is the check c]="Yes")+(AND(ISTEXT(Governance_Master_List__2[Merged Month and Year Due]="January 2023")+(AND(ISTEXT(Governance_Master_List__2[Frequency]="Weekly")))))),"Yes","No")
So, In this example I want the formula to look at [Is the check c] for a "Yes", then Look at the [Merged month and year due] for January 2023, and then look at [Frequency] for "Weekly", and if all 3 of those are met to show the result of Yes onto another worksheet.
So far the formula isn't throwing an error when making it, but it only returns the No result, even when I ensure that all the Weekly, January 2023 entries are showing as Yes.
I'm very new to excel in terms of formulas and am learning as I go. I feel like, because the refernce query table i'm looking at has tons of different values (eg, the frequency has weekly, 6 monthly, monthly, quarterly etc and that there are 12 months to choose from) that the formula is stopping because its looking at and not ignoring those other options, hence the constant false result.
I've tried the following variations with no result..
=IF(AND(ISTEXT(Governance_Master_List__2[Is the check c]="Yes")(AND(ISTEXT(Governance_Master_List__2[Merged Month and Year Due]="January 2023")(AND(ISTEXT(Governance_Master_List__2[Frequency]="Weekly")))))),"Yes","No")
=IF(AND('Imported data'!C1:C200="Weekly")+(AND('Imported data'!E1:E200="January 2023")+(AND('Imported data'!H1:H200="Yes"))),"Yes","No")
=IF(AND('Imported data'!C1:C200="Weekly")(AND('Imported data'!E1:E200="January 2023")(AND('Imported data'!H1:H200="Yes"))),"Yes","No")
The output excel sheet is to show our quarterly compliance reporting, i'm simple trying to automate the process of entering the data into that report, as the teams use a sharepoint list to enter their compliance tasks.
Anyone have a suggestion on how I can get this working? Eventually it'll be used to populate a number of different yes/no report cells based on the relevant month and frequency of the check.

Cumulative/Rolling Sum Blank Dates

I'm currently working on inventory reconciliation, and I've struggling to fill all days of the calendar with the cumulative sum of product we're currently storing:
Inventory level ($). = CALCULATE(SUM(ledger[cost]),FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(ledger[Document Date])))
As you guys might notice it has at least 90% of all dates filled, however if we look closely to the graph, we can appreaciate March 5th of 2016 is missing just due to the fact there was no transaction during that day resulting on a blank value. However I'm trying to accomplish retrieving the previous day balance for those days with no transactions. e.g: for March 5th should have $17,038,462.32 (balance for the previous day March 4th).
I'm trying to work on another clause into the measure with functions such as EARLIER or LASTDATE, however I haven't been succesful.
Any insight or solutions works well thank you. Have a nice day.
You are using a wrong date field in your measure. Change it to the field from the Date table:
Inventory level. =
CALCULATE(
SUM(ledger[cost]),
FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(DimDate[Date])))

Creating a more advanced scheduler

So i am going to be upgrading some scheduler code and it is currently very dumb. I would love to upgrade the code to be similar to Outlook's every Monday at 5 etc. or every third Thursday of the month.
Current schedule system can not specify a day of the week only a period like (daily, weekly, monthly, annually) and can not specify time, or a specific day, like weekly is only on Friday. and the daily is only at 7 am. (so weekly would be Friday at 7 am)
Are there any resources that I can look up to understand how this would work?
My Google searches so far have turned up nothing useful, due to using the word outlook.
Boost.Date_Time should give you the date manipulation functions you need. Should be easier to use their (debugged) code rather than trying to reinvent it.