Sort by month in Power BI. etc: Jan, Feb, March - windows-7-x64

I want to ask how can I sort my chart by month (etc: Jan, Feb, Marc, Apr, ...) using Power BI?
I had try to put this:
CalendarInv = CALENDAR ('KPI', 'KPI[Month]'), today())
but it give me a pop up error:
"The function MINX takes an argument that evaluates to numbers or dates and cannot work with values of type String."
Thank you in advance.

You haven't provided any repro or dummy data, or given any context to the formulas you posted, so I'm going to focus on the main question: how to sort by month.
First up: make sure your source column is of type Date! If it is a string, do a conversion in the query, model, or a new derived column, and work from there.
I'm assuming that you fixed that, and that you have something similar to this dummy data:
InvoiceDate;Value
2017-09-01;200
2017-09-16;300
2017-10-01;250
2017-11-01;230
2017-09-25;150
Now, there are several derived columns I suggest for easy month-based sorting:
MonthNr = MONTH([InvoiceDate])
MonthNrWithName = FORMAT([InvoiceDate]; "MM (mmm)")
YearMonth1 = YEAR([InvoiceDate]) & "-" & IF(MONTH([InvoiceDate])<10;"0";"") & MONTH([InvoiceDate])
YearMonth2 = FORMAT([InvoiceDate]; "yyyy-MM")
Here's what they look like in graphs:
I personally prefer option 4, usually.

Related

Google Sheets - DATE format not working on imported Date in TEXT format

I text based .csv file with a semicolon separated data set which contains date values that look like this
22.07.2020
22.07.2020
17.07.2020
09.07.2020
30.06.2020
When I go to Format>number> I see the Google sheets has automatic set.
In this state I cannot use and formulas with this data.
I go to Format>number> and set this to date but formulas still do not see the actual date value and continue to display an error
Can someone share how I can quickly activate the values of this array so formulas will work against them?
I would be super thankful
Where the date are in column A, starting in cell A1, this formula will convert to DATE as a number, after which you apply formatting to Short Date style.
=ARRAYFORMULA(IF(A1:A="",,DATE(RIGHT(A1:A,4),MID(A1:A,4,2),LEFT(A1:A,2))))
Hopefully(!) the dates stay as text, otherwise Google Sheets would sometimes detect MM/dd/yyyy instead of dd/MM/yyyy, and you won't be able to distinguish between July 9th and September 7th in your example.
Solution #1
If your locale is for instance FR, you can then apply
=arrayformula(if(A1:A="";;value(A1:A)))
solution#2
you can try/adapt
function importCsvFromIdv1() {
var id = 'the id of the csv file';
var csv = DriveApp.getFileById(id).getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
csvData.forEach(function(row){
date = row[0]
row[0] = date.substring(6,10)+'-'+date.substring(3,5)+'-'+date.substring(0,2)
})
var f = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
f.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First thanks to those that suggested a fix. I am not really a programmer and get cold sweats when I see suggesting of running scripts to solve simple problems. Sorry guys.
So the (non programmer) solution with the dates was to do a find/replace (CTRL + H) and replace all the (.)dots with (/)slashes, then to make sure the column is formatted as a date, then Google finally understands it as a date.
With the accounting values as well, I had to do the same find/replace to remove all the ' between thousands, then google woke up and understood them as numbers.
I am significantly underwhelmed by this from Google. They are getting too fat and lazy. They need some competition.

The difference in strings in Tableau

I am using Tableau Server version 10.4.3
I have a dimension rTime which has string value. the entries in rTime is of like this
May 10, 2019 8:59:56.303 PM UTC
I want to check whether the rTime is today or not. I cannot use DateParse since my server doesn't have this functionality.
I created a calculated field CheckrTime with below content :
STR(LEFT(SPLIT([rTime],':',1),LEN(SPLIT([rTime],':',1))-2))
When I am dragging CheckrTime into workspace area, the output is coming in below format which is what I wanted :
May 10, 2019
When I am checking ISDATE("May 10, 2019") (a normal string), it is outputting TRUE as expected but when I am checking ISDATE(CheckrTime) it is outputting FALSE . Why?
The reason I am checking above thing is I am looking to use DATEDIFF function of tableau in this way:
DATEDIFF('day', DATE(CheckrTime), TODAY()) == 0
NOTE
If someone is wondering ,I have taken care of the level of granularity.
If you have a better solution then the one I am following, please do tell me.
This is working for me. I would expect May 10 <> May 16 (today) and therefore return false. However, when I change your example to today's date it does in fact come back as true.
You could also try this formula for the date LEFT([rTime],FINDNTH([rTime],' ',3)). It is slightly less complicated but will give you the same answer.
Calculated field (date type) depends the locale used which defines date format. Are you able to use Date function?
In Tableau website there is a example using english locale
For string 06May2017
DATE (LEFT([Original Date], 2) + "/" + MID([Original Date],3,3) + "/" + RIGHT([Original Date],4))
Above mentioned highligts / character between digits which is depending on locale

Create date from day, month, year as integers in KDB Q

I am trying to get a date from its integer components: I have day, month and year as variables (that can change, I don't want to hard code them), and I want to reunite them in a date variable.
For example, something like that;
myDay: 15
myMonth: 4
myYear: 2016
`date$(myYear,myMonth,myDay) --> should return 2016.4.15 (formatted as a date).
Any way to do that?
Thank you
q)d:3
q)m:8
q)y:2016
q)"D"$"." sv string (y;m;d)
2016.08.03
See cast vs tok - need to use different arguments depending on if what you're casting from is a string or not

In Julia, if date is 96, how can I make it 1996 in DateTime?

I have an array with strings of dates. The format is "2/27/16 3:47" so "m-d-y H:M". However, DateTime parses this as 0016-27-02T03:47:00. I would like to have the output be: 2016-27-2T03:47:00.
My code is:
map(date-> DateTime(date, "mm/dd/yy HH:MM"), datsub[:date])
Side question: The output type becomes Any. Is this the correct type or should it be DateTime or something similar?
As #akrun mentioned, you should add the year yourself:
Dates.Year(2000) + DateTime(date, "m/d/y H:M")
This is more explicit about exactly what is happening. Otherwise Dates would have to guess what exactly something like 97 means: 1997 or 2097, or actually year [00]97?
It's possible that you might want to come up with a reasonable cutoff for what year to add. You can try the following:
expandyear(date::DateTime) = date + (Dates.year(date) < 25 ? Dates.Year(2000) : Dates.Year(1900))
with whatever cutoff you think makes sense.
The issue with return types with map is a known problem that has been fixed in the latest v0.5 nightlies. Julia v0.5 is likely to be released in the near future, perhaps within several months.

How can I add several months to a date coming from a date form field?

With DateJS, you'd add e.g. six months to the current date like this:
Date.today().addMonths(6);
However, I need to add 24 months not to today's date, but to a date which a user has typed into a date field. So the today() should in principle be replaced by something like this.getField('begin_date').value.
The result shall be written into another data form field.
I tried hard, but couldn't make it. Can anyone help me out?
Providing the input value is a textual representation of a date, you need to convert it into a Date object at the first place. Then you can work with it as you want.
DateJS has a pretty smart parse() function which does exactly that, so you'd achieve it like this:
Date.parse(this.getField('begin_date').value).addMonths(24)
When a specific date format is needed, like DD.MM.YYYY commonly used in Europe, you can use parseExact() and specify the format. Like this:
Date.parseExact(dateToParse, 'dd.MM.yyyy') // leading zeroes required; parses 01.04.2014 but not 1.4.2014
Date.parseExact(dateToParse, 'd.M.yyyy') // leading zeroes not required; parses both 01.04.2014 and 1.4.2014
Here is a solution that I found for my problem, using DateJS as well:
start = this.getField('begin_date').value;
var d1 = util.scand("dd.mm.yyyy", start);
var myDate = new Date(d1);
result = myDate.addMonths(24);
This works pretty fine, also spanning leap years, except for the 28th of February, 2014/2018/2022 ... ; the result then will be the 28th of February, 2016/2020/2024 ... and not the 29th of February 2016/2020/2024... In these cases it's up to the user to accept the 28th or to manually change the date to the 29th.