I have a formula in Excel to calculate total time between start and end date.
Here is the formula
=IF(M2="","",IF(((M2-L2)*24-12<=12,12,(M2-L2)*24-12))
I would like to use it in PowerBI using DAX formula.
I tried this
column = HOUR('Logs'[Finish Date]-HOUR('Logs'[Start Date]))*24-12
But the value is different with excel calculation.
Anyone can give idea please? I am really new with DAX.
Thank you so much
If you have datetime data type for your column "Start Date" and "End Date", in transformation layer you can simply add a new column as below and this will return your expected output.
You can still create measures in the report level as below-
hour_diff = DATEDIFF(min(time_diff[Start Date]),min(time_diff[Finish Date]),HOUR)
Output will be same as below-
You can check this blog for more examples.
column =
SWITCH(
TRUE()
,IF ([start]=BLANK()||[end]=BLANK(),TRUE(),FALSE()),BLANK()
,DATEDIFF([start],[end],HOUR)<12,12
,DATEDIFF([start],[end],HOUR)
)
Second solution:
column =
IF(
[start]=BLANK()||[end]=BLANK()
,BLANK()
,DATEDIFF([start],[end],HOURS)*24-12
)
Related
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] )
Tableau will generally show every single date within table output of the date ranges filtered for. Is there a way to only show the first and last date in the table for the date of ranges selected?
I created an image of the desired output in excel. Link below:
Desired output example
Thank you in advance!
The feature that will address your goal is called a Level of Detail (LOD) calculation. They have many uses and take various forms. I suggest reading about the in the online help.
But, to answer your question, the LOD calc to find the first (i.e. minimum) value in a date field called, say, Transaction Date, is;
{ MIN([Transaction Date]) }
The formula for the latest value is left as an exercise for the reader 😊
As a data analyst, I would like to see the report in a pivot table automatically for the current month, so that I can take a look at it and don't have to change the date filter manually.
This is the formula to show the first day of the current month. (Which is the criteria I need, first of the current month)
=EOMONTH(today(),-1)+1
It works when I put this formula in any cell.
But when I put it in the pivot "filter by condition" option it doesn't work.
This is what I tried.
Text is exactly =EOMONTH(today(),-1)+1 (In formula box)
The date is exactly =EOMONTH(today(),-1)+1 (In formula box)
Here a screenshot of the options
Any help will be greatly appreciated.
I've never had great luck with the pivot table filter criteria in Sheets, I typically filter the data first if it's more advanced or use aggregating functions. In the Sheets pivot tables are better for quick analysis than dashboards.
There's probably a few ways to do it, but one of the easier ways would be to duplicate the data tab, clear the data and use a filter function to retrieve data. Update the Pivot table data source to the new tab. This will always only be the current month's data.
Basically you filter the data before the pivot table, with the [filter function][1].
=Filter(data , [date col]>=EOMONTH(today(),-1)+1 , [date col]< date(year(today()), month(today())+1,1)
You can also add a month column to the data and then filter on that column, however each month you would need to update the month filter in the pivot table.
=date(year([date cell]),Month([date cell]),1)
If you're using it for a 'dashboard' of sorts, I would generally recommend to create it yourself with aggregating formulas (sumifs, countifs, ect) and then you can use the more complex filters.
try custom formula:
=MONTH(A2)=MONTH(TODAY())
where A2 is first cell of column containing valid dates
You can try to Filter by a Custom Formula:
=month(DatePurchase)=month(TODAY())
Where DatePurchase is the Field Name.
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))
I am new to JasperReports and iReport, and I am facing a problem. Before going through the question, first, please take a look at the following image:
So, the main problem is with the cumulative columns. Per say, the "Cumulative Bill" column should show the following values sequentially:
6000.0, 14000.0, 23000.0, 32800.0, 42800.0 and 45800.0
I have no idea how this can be done. I tried creating a new variable, but there is no cumulative type calculations there. Please assist me.
Create variable $V{variableName} with calculation = Sum and Variable expression = $F{BillAmountField} and put text field with this variable into detail section.
Is it so hard? :)
It can be done at the query level, here is the query :-
SELECT m.bill_amount,
#cbill:=#cbill+ifNull( m.bill_amount,0) cumulative_bill
FROM (
SELECT #cbill:=0,
bill_amount
FROM
)m