translate from excel formula to power bi DAX - powerbi

I have this excel formula, how can I get around to translate this into a Power BI Measure in DAX. Also in excel we have the Today() function, how can I define 'today' in Power BI DAX?
=IF(ISNUMBER([#[StartDate]]),
IF(ISNUMBER([#ActualStartDate]),IF([#ActualStartDate]-[#[StartDate]]>=1,"Late",IF([#ActualStartDate]-[#[StartDate]]<0,"Early","On-Time")),
IF([#[StartDate]]>TODAY(),"Targeted","Running-Late")),
IF(ISNUMBER([#ActualStartDate]),"Started","Not-Started"))
Just wonder Is there an Excel to DAX translator available :)
I managed to create a calculated column, as below. I wonder if it is possible to create this as a "Measure" instead.
Calc_Status_col = if(isnumber('table'[planned_start].[Date]),
if(ISNUMBER('table'[actual_start].[Date]),if('table'[actual_start].[Date]-'table'[planned_start].[Date]>=1,"Late",if('table'[actual_start]-'table'[planned_start].[Date]<0,"Early","On-Time")),
if('table'[planned_start].[Date]>TODAY(),"Targeted","Running-Late")),
if(ISNUMBER('table'[actual_start].[Date]), "Started", "Not-Started"))

Related

How does one count the number of columns in a table in Power BI using Dax

In Power BI desktop this is my 'Table1':
How do I count the columns (not rows) using DAX? Ideally this would be a measure called ColCount.
The end results should be ColCount=4. I have tried invoked functions, but new tables are unwanted.
DAX doesn't really have a method for that.
PQ/M has this method:
let
Source = Table.ColumnCount
in
Source

Replicate sumif formula across a row in Power BI

Is there a way to replicate the formula below in excel onto a Power BI measure?
I want for each company to return the total number of countries it applied for.
Many thanks in advance
Nasos

Converting a column in Spotfire to Power BI

hi I am trying to redo an analytic which is already there in Spotfire to Power Bi. There is calculated column Max([ Date]) over ([ContentId]) .
Can anyone help me with converting this calculated column in Power Bi
You could use something similar to the following calculation:
Calc_Column = CALCULATE(MAX(Table[Date]),ALLEXCEPT(Table,Table[ContentID]))
Replace "Table" with the name of your table and you should be good to go. Hope this helps.

How to change dataype of calculated column number to text in power BI

I have a power bi report with live connection to the SSAS cube. I have a numeric column which I wanted to convert to text using DAX, since its a live-conection i cannot change this on power bi end. is there a way ?
You can use the format function in dax,
For example you can add a new column as the following example:
New_Column = FORMAT(Table1[NumericColumn];"General Number")
Get this example from the source in Pre-Defined Numeric Formats for the FORMAT Function
Hope this can help you!

Power BI - SQL to DAX?

I have an rdat field that I have to convert to a date field which I know how to do in sql but am new to DAX and I'm not sure how to do this
CONVERT(CHAR(10), DATEADD(d, RDAT_ENTERED +5843, 0), 1)
in Power BI. I can fix on the sql side so that it just brings in the data but I would still like to know how this would look in BI.
It seems your data uses the SQL SERVER EPOCH to represent dates so RDAT_ENTERED + 5843 means a determinated number of days from 1/1/1900. You can use that information to convert it to human dates via DAX or Power Query.
Create a calculated column either in Dax or Power Query (informally known as "M")
DAX in Power BI and Power Pivot
HumanDate = DATE(1900,1,1) + [RDAT_ENTERED] + 5843
M language in Power Query
=Date.AddDays(DateTime.FromText("1900-01-01"), [RDAT_ENTERED] + 5843)
I realize the context of your question and recognize the excellent answer by #alehandro. However, a few suggested best practices:
SQL is a BI tool
Transformations to standard data types should be at as low a level as possible
Magic numbers should not be used DECLARE #EPOCH_RDAT DATE = { d '1916-01-01' };
Function parameters should be used as intended: SELECT DATEADD(DAY, RDAT_ENTERED, #EPOCH_RDAT);