Power BI convert eight digit yyyymmdd to date using DAX - type-conversion

I'm trying to convert eight digit yyyymmdd to date format with DAX function.
column = DATE(LEFT(TABLE[COLUMN],4),MID(TABLE[COLUMN],5,2),RIGHT(TABLE[COLUMN],2))
However, I've got an error because of the original column has some records with "00000000", so how can I make a default value with IF statement or are there any better solution?
Best regards

What I typically do is just make 2 distinct Power Query steps and this is handled automatically.
just make the yyyymmdd column a text column
make the text column from step 1 a date column (when prompted, be sure to select 'Add New Step')
replace errors with null
That's it. You can even Ctrl-Click to select multiple columns and combine them into the 1,2, and 3 steps with multiple columns.

Please check out "ferror" function IFERROR(value, value_if_error) for more information please visit Microsoft MSDN with link below
https://msdn.microsoft.com/en-us/library/ee634765.aspx
column = IFERROR( DATE(LEFT(TABLE[COLUMN],4),MID(TABLE[COLUMN],5,2),RIGHT(TABLE[COLUMN],2)), DATE(yyyy,mm,dd))

Related

Sum Up Values from the Same Date Google Sheets

I am looking to sum up the values from different cells which occur on the same date. I wish to use the dates from column E and the values from column B.
For example- date 11/09/2022 should add up to 14,919.8 but on the formula I used from a previous answer it results in 36945.4. What do I need to do to change this?
I have tried to use previous answers to resolve this issue but was unsuccessful.
The sheet can be found here if you wish to play around with it:
https://docs.google.com/spreadsheets/d/11RjGeyOIpGS2q7fDmG0bgniQxibCGe9f-xHi-tmVexc/edit?usp=sharing
Thanks for your help
use:
=QUERY({E3:E, B3:B},
"select Col1,sum(Col2)
where Col2 is not null
group by Col1
label sum(Col2)''")

Google Sheets - Expanding dataset according to months between 2 dates

I would like to be able to expand a dataset to include one row per "person" per month, filtered by Start and End Date.
Consider the example below:
This is the desired outcome
Inputs are a start and end date, which could be anywhere between the start of a given financial year (01/04/20XX) and the end of that financial year (31/03/20XY).
The output rows contain each month comprised between these 2 dates for which there is a matching entry in the input (see example output)
I have an example sheet here.
Any help would be appreciated, thanks
Try:
=ARRAYFORMULA(SPLIT(UNIQUE(QUERY(FLATTEN(IF(DAYS(C2:C4,B2:B4)>=SEQUENCE(1,1000,0),A2:A4&","&TEXT(B2:B4+SEQUENCE(1,1000,0),"YYYY-MMM")&","&D2:D4,"")),"where Col1 is not null")),","))
Result:
This works however the only limitation is you have to manually edit the formula to specifically define the End range. It crashes when I set it to use the whole column using the formula below:
=ARRAYFORMULA(SPLIT(UNIQUE(QUERY(FLATTEN(IF(DAYS(C2:C,B2:B)>=SEQUENCE(1,1000,0),A2:A&","&TEXT(B2:B+SEQUENCE(1,1000,0),"YYYY-MMM")&","&D2:D,"")),"where Col1 is not null")),","))
I am assuming this is because of the Query function which runs a Google Visualization API Query Language query across data making it very long and heavy processing.
Explanation:
To explain how this works using the formula from this link: Google sheets - List of dates between a list of start and end dates to get the dates between, but I changed the IF to return all combined 4 columns. Converted it to date format using TEXT (YYYY-MMM). I then used the UNIQUE to remove duplicates so it will only show the months. Then make use of SPLIT to split across 3 columns.
References:
Get dates between 2 dates
TEXT
UNIQUE
QUERY
SPLIT
Hope this helps!

How can I add a dynamic date column on Power BI

I have a question on Power BI, basically i have a column with date (HIREDATE), and my task is to add a column that calculate the difference between the ACTUAL date and the date on my column. So it needs to be dynamic.
I watched some youtube videos but haven't found a case like mine, even though i think it's a common, not very rare task.
Following a tutorial on Youtube and on Microsoft WebSite I added a custom column named Experience with the following code :
= Duration.ToRecord ( YEAR(TODAY()) - [#"Date d'embauche"]) /* Date d'embauche = HIREDATE in french*/
It shows me :
No syntax errors have detected
But when I click on
OK
It shows me this :
Expression.Error: The name 'YEAR' wasn't recognized. Make sure it's spelled correctly.
Please help me solve this.
For Power Query you would need DateTime.FixedLocalNow() to get the date time, then wrap that function with Date.Year to extract the year, so you would have the following:
Date.Year(DateTime.FixedLocalNow()) - Date.Year([#"Date d'embauche"])
in this example, the formula is used in a custom column, to give the time difference in years.
Normally it is best to do these sort of transformations in Power Query before getting to the data model.
Probably you are adding the Custom column in Power Query. I would rather recommend to add a Calculated Column through the following DAX expression:
Date difference =
YEAR (
TODAY ()
)
- YEAR ( 'Table Name'[HIREDATE] )

Separating dates between a date range in Google Data Studio

I have two dimensions in Google Data Studio in the format Date (From,To) from an external source and now I want to display all days within the time space individually.
Ex: 01.10.2020 - 05.10.2020
---result as table---
01.10.2020
02.10.2020
03.10.2020
04.10.2020
05.10.2020
That's it. I just can't find a solution.
I understand that your ultimate goal is to join the two dates into a single field in the format 01.10.2020 - 05.10.2020.
To do this, you can create a new field that contains the formula:
CONCAT(Date1, ' - ',Date2)
And after, insert this new field in your table. The output format of this formula will be a text type element.

Expression to create SSRS column dynamically

I need an expression to take an existing column and recreate this column over and over before another column/s where the column name contains either "Monday" or the date of the column falls on Monday.
The reason I need this expression is to repeat a header column in a pivoted report that is pivoting start/enddate parameter. So if a user selects to run the report for this month, they should get 31 columns (for each date/day) and header repeating before every Monday.
Make sure your dataset contains all the dates in your date range. If not create a date table and cross join to it. Don't pivot the results, let SSRS do that bit. Once your dataset has all the dates, you can use a matrix in your report and drop the date colum into the column group. This will give you one column for each date in your dataset. I'm not at my PC at the moment but if you need any more help, show an example of your dataset and I'll put together a quick sample report.