"Last Week" Date Conditional Styles in Jasper Reports - styles

I am trying to create a style that makes dates from the last week in bold. I have only been able to get it to work by putting in an explicit date like below. I would like to have a dynamic "last week" based on the current date.
<style name="Date_Bold" isBold="false">
<conditionalStyle>
<conditionExpression><![CDATA[$F{$F{account_date}.toString() > '2011-10-17 00:00:00']]></conditionExpression>
<style isBold="true"/>
</conditionalStyle>
</style>

You can try this expression to get 'last week' (today minus seven days)
<![CDATA[new Date(System.currentTimeMillis() - (7 * 1000 * 60 * 60 * 24))]]>
You can see also this link for better understanding this solution.
You can try to get date via SQL query and put the result value to the new Date field.
It would be something like this for Oracle:
SELECT account_date, sysdate-7 as last_week, ... FROM table ...
It would be something like this for MS SQL:
SELECT account_date, (GETDATE() - 1) as last_week , ... FROM table ...
Another way to pass date from code via parameter.
Or you can try to import Joda library for example. Here is the sample of scriplet using.

Related

Translating excel formula into power query language

Could someone please assist with helping me create a formula using Power Query that performs the same as the following Excel formula?
=iferror(iferror(if(value(left([Qualifications],1))>0,right([Qualifications],len([Qualifications])-7),""),left([Qualifications],find("/",[Qualifications])-4)),[Qualifications])
Essentially I am trying to strip out expiration dates from a column which contains the qualification title and expiration date (if any) at the end of the title, ideally to just show the qualification title. As some of the qualifications use () in the title, I need to search for the presence of / in the title and remove characters around these.
As I'm new to using Power Query, it's proving a little time consuming trying to learn and understand the different language to Excel!
EDIT - This is the Token Eof error I receive when pasting the provided code:
enter image description here
EDIT 2 - This is the error that is showing in multiple rows, including the row with the date at the end
enter image description here
A powerquery solution .. Assuming you want to remove (##/##/####) then
Paste below into a blank query in home ... advanced editor ... name it RegExReplace and then file .. close and load
/*
https://www.mathscinotes.com/2020/02/power-query-regular-expression-hack/
Mark Biegert
Modified version of regex routine documented by Imke Feldman at
https://www.thebiccountant.com/2018/04/25/regex-in-power-bi-and-power-query-in-excel-with-java-script/
Input Parameter:
x : String to be searched
y : Search regex
z : Replacement regex
*/
(x,y,z)=>
let Source = Web.Page(
"<script>var x="&"'"&x&"'"&";var z="&"'"&z&
"'"&";var y=new RegExp('"&y&"','g');
var b=x.replace(y,z);document.write(b);</script>")
[Data]{0}[Children]{0}[Children]{1}[Text]{0}
in Source
Then in your data to clean, Add column .. custom column .. with formula
= RegExReplace([YourColumnName],"\\(\\d{2}\/\\d{2}\/\\d{4}\\)","")

Create Date from MM/DD format and include current year? Power Query

I have a table that has a series of Columns with data I need to split out. Example below
STATUS#10/16 12:00:00 (CODE)
I've been able to split it easy enough and when I originally tried to set the date on an older dataset it identified it as a date e.g. 16th Oct 2021 However I started to get errors on this date column and trying with different datasets (10/12, 10/13, 10/14) it is not finding the date. I tried the following query code but I'm receiving errors
[STATUS DATE] is split to 10/14, 10/15 etc
#date( Date.Year(DateTime.LocalNow), Date.Month(Text.End([STATUS DATE]), 2), Date.Day(Text.Start([STATUS DATE]),2))
However I'm getting a function error so I tried
Date.From(Date.Day(Text.Start([STATUS DATE]),2) & Date.Month(Text.End([STATUS DATE]),2) & Date.Year(DateTime.LocalNow)
I have also tried to do this from an example column however the query created is looking at the cell value e.g. if 10/14 then 14/10/2021 else if 13/10 then 14/10/2021. This method i feel is prone for error once I include a larger dataset.
Is there anyway I can determine the date value based on mm/dd format? But with year end in mind, make the YYYY be determined by current year unless we move into Jan and then I don't want the Oct, Nov, Dec value showing as 2022.
You don't really show what your original data looks like.
But if it is like:
Source
Then you can use this code in the Add Custom Column dialog:
let
split=Text.SplitAny([STATUS DATE],"#/ "),
mnth = Number.From(split{1}),
dy = Number.From(split{2})
in
#date(Date.Year(DateTime.LocalNow()),mnth,dy)
The Text.SplitAny function lets you input a list of delimiters and the text will split on all of them. So it is relatively simple to extract the month and day values
to create:
Split [STATUS DATE] one more time into [Month] and [Day] column, using the "/" as a separator. Then you don't have to bother with 1 or 2 digit numbers and you can simply use this formula:
#date(Date.Year(DateTime.LocalNow()), [Month], [Day])
DateTime.LocalNow() is a function, so you need to add the brackets.
[Month] and [Day] are numbers already, so you don't need the Date.Month() or Date.Day() functions.

DAX LASTDATE Formula With Criteria

Please Help.
My table (TestTable) has the following columns - Individual / Date / Pct. Achieved.
I am trying to use the LASTDATE function to work out when an individual last achieved 90% or above.
My forumla thus far is as follows;
=CALCULATE(LASTDATE(TestTable[Date]),FILTER('TestTable',[Pct. Achieved]>0.895))
This works but only shows when the last individual achieved >90% and uses that date for everyone else. However, I would like it to look at each individual separately and return a date for when that individual last achieved >90%.
Thanks in advance.
If you want it split by individual, then you'll need to add the individual to your filter:
CALCULATE (
LASTDATE ( TestTable[Date] ),
FILTER (
TestTable,
TestTable[Pct. Achieved] > 0.895 &&
TestTable[Individual] = EARLIER ( TestTable[Individual] )
)
)
Note: EARLIER has nothing to do with dates but rather refers to the earlier row context (rather than the row context within FILTER).

Excel Using concatenate to compare dates

I have a table containing several columns of which one is a date/time field. I am trying to get a count of instances per day using the following
=COUNTIFS(Table4[Data],"Apple",Table4[Date],(CONCATENATE(V4,"*")))
Data Date Comp Date Count
Apple 6/12/18 1:00 PM 6/12/18 12:00 AM 0
Apple 6/12/18 7:00 AM
Orange 6/12/18 1:30 PM
Apple 6/11/18 11:23 AM
From my understanding of all the moving parts here I should be checking to see if "Apple" exists in the data column and then if "6/12/18" with any amount or type of characters after it exists. If both are true I will then get a count + 1 leaving me with a value of 2 in the above example.
What I actually get however is a 0 unless I match the time portion of date the data to be exactly the same and then removed the wildcard ,"*" from the equation.
Am I doing something wrong or can the wildcard not be used to accomplish what I am trying?
Thanks!
I think you should set your criteria properly.
If you add an additional column next to your Date that contains calculates the integer value of your date using INT() and format the display as DATE (m/d/yyyy) you should then be able to use the following COUNTIFS formula
=COUNTIFS(Table4[Data], "Apple", Table4[Date], "=6/12/18")
See the explanatory video from their Office' support site: https://support.office.com/en-us/article/countifs-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842
If your [Date] column is a datetime or smalldatetime, you can work with it using CONVERT function, depending on how you want to group.
For example, if you don't care about the time to do the group, you could use the next query:
SELECT CONVERT(varchar,[Date],103), [Data], COUNT(*)
FROM [test_delete].[dbo].[Table1]
GROUP BY CONVERT(varchar,[Date],103), [Data]
This should result in something like this:
[Date] [Data] [Count]
11/06/2018 Apple 1
12/06/2018 Apple 2
12/06/2018 Orange 1
Hope this helps you
If your dates are stored as dates instead of text, use the following:
=COUNTIFS(Table4[Data],"Apple",Table4[Date],">="&V4,Table4[Date],"<"&V4+1)

Excel--SUMPRODUCTIF? Work around?

I am trying to calculate how many class registrations my company has received per month, per year. ]
So far, I've been able to do this using SUMPRODUCT, (for example:
=SUMPRODUCT(--(DATE(YEAR($A$2:$A$10),MONTH($A$2:$A$10),1)=DATE(2013,1,1))))
but it is a lot and I'm hoping there's an easier way.
I have about 16,000 Registrations total to sort through with registration dates ranging from 2003 to 2014. Each registration has the following info:
the Registration Date, Course Name, Class Date, Name, Title, Company, City, State, Type, and Paid.
What I really want to be able to do now is show how many class registrations we received per month, per year but separate it out for both private and public types. I have not figured out how to do this yet.
Please help!
I tried to include an image of part of my current excel spreadsheet, but it said the site told me I need "at least 10 reputation to post images"
You can still use SUMPRODUCT.
You could use the following:
=SUMPRODUCT((YEAR(A1:A3)=2013) * (MONTH(A1:A3)=1) * (F1:F3 = "Private") * 1)
And:
=SUMPRODUCT((YEAR(A1:A3)=2013) * (MONTH(A1:A3)=1) * (F1:F3 = "Public") * 1)
Where A1:A3 is the range that has your dates and F1:F3 is your flag that denotes public or private courses.
You can also alter the formula to:
=SUMPRODUCT((YEAR(A1:A3)=YEAR(G3)) * (MONTH(A1:A3)=MONTH(G3)) * (F1:F3 = "Private") * 1)
Where Cell G3 is any day in the month/year you want to calculate for.

Resources