Date formula Power Query - powerbi

Oi,
I'm trying to add a new column to my Power Query containing a fixed text & date (MMYYYY) and i keep getting errors while doing so.
Example of what i need is : "TEST 032022" --> Test is Fixed ; 03 is formula ; 2022 is formula
Does anyone know how to fix this?
Thanks!

You need to turn the Numbers into text, using the Date.ToText function or Number.ToText
So for your MM you would need some thing like this, assuming you have a date column
Number.ToText(Date.Month([Date]), "00")
Which gives months 01 to 12
Or
Number.ToText(Date.Month(DateTime.LocalNow()), "00")
Using the current date time "03"
For your example you would need
"TEST " & Number.ToText(Date.Month(DateTime.LocalNow()), "00") & Number.ToText(Date.Year(DateTime.LocalNow()))
Which outputs TEST 032022

Related

How can I see the data of the last 3 months as a total in Power BI?

I am the new one at the Power BI platform. :) I have a question about like 'data of the last 3 months '
I have a dataset with columns weekdate and total hours. What I want to do is to see the data of the last 3 months (we are in June now, the format I want is to see June May April) in total form. So summing the totalhours column by the weekdate column. I tried a code like this, but I couldn't get the result I wanted:
Column = CALCULATE(SUM(works_by_type_for_week[TotalHours]),DATESINPERIOD(works_by_type_for_week[WeekDate],LASTDATE(works_by_type_for_week[WeekDate]),-3, MONTH))
And I tried like this but it still didn't work:
Column = CALCULATE(SUMX(works_by_type_for_week,IFER*ROR(VALUE(works_by_type_for_week[TotalHours]),0)),DATESINPERIOD(works_by_type_for_week[WeekDate],LASTDATE(works_by_type_for_week[,M*ONTH-3])),
I am getting an error like this:
the function sum cannot work with values of type string
I hope I was able to explain. :) Your help is very valuable to me...

Power BI text to date in "mmm-yy" format

I have an excel file having a column with Text format values like Jan-18, Dec-19, Feb-20. I want to convert it to a date format but when I am trying to make this column a date format it printing 1/18/2021, 12/19/2021,2/20/2021. Basically its considering Jan as month(1), 18 as Date, & making all year as 2021 deafult.
Can someone help?
Original(text) After Date conversion Desired format
Jan-18 1/18/2021 01/01/2018
Feb-19 2/19/2021 01/02/2019
Mar-20 3/20/2021 01/03/2020
You can try,
DATE(2018, MONTH(convertedDate), 1)
This will convert your converted date to the first day of the relevant month in 2018. This is stored in Power BI as a datetime object. If you want to show that value in dd/MM/yyyy format you can do it by selecting correct Format in the top menu.
If you load in the Original column as text, try this trick:
Desired format = DATEVALUE ( "1-" & [Original] )
Appending the "1-" to the beginning gives it a day of the month and forces it to recognize the last digits as the year.
I faced with the same issue , while changing the format instead of using Date use the last option i.e "Using Locale... " -> in that change the Data Type from Text -> Date, and Locale to English(United Kingdom) -> Hit ok. Earlier Format ,What should be the desired format .This worked for me!

DAX Query to Return Text Value as of 1 Month Ago

I am looking for some assistance, i am trying to create a DAX formula that will return a text value as of 1 month ago / the last entry date in a range of dates.
From the example table you see a list of codes in [JCS Grade] what i am trying to do is insert a new calculated column that will insert the previous months [JCS Grade] value, for example Employee Number 111 on Item Date 01 August 2019 has a [JCS Grade] = M2 and on 01 July they have a JCS Grade Value of M1 and i would like to return that previous months value in a calculated column [JCS1MonthAgo] but currently this is not working for me and i have tried the formula:
JCS1MonthAgo = CALCULATE(FIRSTNONBLANK(Sheet1[JCS Grade],DATEADD(Sheet1[Item Date],-1,MONTH)))
But this formula does not work as it only returns the current row value and not the prior months!
if anyone could spare a moment to assist me it would be greatly appreciated.
Many Thanks
Chris
You could use variables to do this calculation:
JCS1MonthAgo =
VAR EmpNo = Sheet1[Employee number]
VAR ItemDate_Previous = EDATE(Sheet1[Item Date],-1)
RETURN CALCULATE(MIN(Sheet1[JCS Grade]),
FILTER(Sheet1,Sheet1[Employee number]=EmpNo),
FILTER(Sheet1,Sheet1[Item Date]=ItemDate_Previous))
The idea is to apply a filter to get the correct employee number and the date of the previous month. Hope this meets your requirements.

month name not working by using format function in power bi

I have used the following to get the stating day of the month
multiemp[Day] - WEEKDAY(multiemp[Day],2)
For example if my date us 22 May 2018, after using the above query, got the expected out put.i.e., 20 May 2018
Now I tried to get the month name by using the above query and format function
format(month(multiemp[Day] - WEEKDAY(multiemp[Day],2)),"mmm")
results were not expected, instead of may January is getting populated.
when verify with the following month function expected results arrived .i.e, 5
month(multiemp[Day] - WEEKDAY(multiemp[Day],2)
but only issue in changing the month number to month name
Please find below:
formulas used
weekstartday = multiemp[Day] - WEEKDAY(multiemp[Day],2)
weekstartday_month = month(multiemp[weekstartday])
Month_name = format(multiemp[weekstartday_month],"mmm")
another_ans = format(dateadd(multiemp[Day],-weekday(multiemp[Day],2),day),"mmm")
another_answer_date = dateadd(multiemp[Day],-weekday(multiemp[Day],2),day)
EDIT: Day 2
Modified the datatype of the column to date time/timezone.
after refresh the data didn't change
Found out the solution
Solution 1:
mnname = format(multiemp[weekstartday].[Date],"mmm")
Solution 2:
Month_name = format(date(YEAR(multiemp[weekstartday]),MONTH(multiemp[weekstartday]),day(multiemp[weekstartday])),"mmm")
Thanks in advance
Format the column instead of repeating the column DAX statement.
Column = FORMAT(*nameOfYourStartOfWeekColumn*,"mmm")
Because FORMAT(...,"MMM") or FORMAT(...,"MMMM") takes as an argument a date types and non numeric types, try this
format(dateadd(multiemp[Day],-weekday(multiemp[Day],2),day),"MMM")
If you want the starting day of the week as monday, then,
format(dateadd(multiemp[Day],-weekday(multiemp[Day],3),day),"MMM")
EDIT
Verify that date column is date or date\time type.
Solution 1:
mnname = format(multiemp[weekstartday].[Date],"mmm")
Solution 2:
Month_name = format(date(YEAR(multiemp[weekstartday]),MONTH(multiemp[weekstartday]),day(multiemp[weekstartday])),"mmm")

Sharepoint 2010 Task list: Due date = Start date + 1 month

I want to auto-fill the Due date column by taking the Start date column and add 1 month to it.
This formula I've tried in different ways:
=DATE([Start Date]+[Gap],"dd-mm-yyyy") (I created Gap column as number type and filled it with 28 days; in our language, dd-mm-yyyy seems to be the usual way of showing dates in Sharepoint).
Sharepoint keeps on giving back errors.
Try this formula:
=DATE(YEAR([Start Date]);MONTH([Start Date])+[Gap];DAY([Start Date]))
where [Gap] value is integer.
Note: pay attetion to delimiters - they are locale-dependent, most probably you need to replace , with ;