How do I convert Excel to DAX Formula? - powerbi

In my current project I am migrating Excel reports to Power BI, I need help converting the Excel formulas to DAX
Excel
COUNTIFS($K:$K,"*",$L:$L,E$31,$CS:$CS,1$D:$D,$E$15)
SUMIFS($AU:$AU,$L:$L,E$31,$CI:$CI, "Yes",$D:$D,$E$15)/1000
IFERROR((SUMIFS($AU:$AU,$L:$L,E$31,$CI:$CI, "Yes",$D:$D,$E$15,$P:$P," Key Launch Under Existing Hero")/1000)/E36,0)
COUNTIFS(`$BH$11:$BH$1001,"Commercial Innovation",$H$11:$H$1001,F$31,$C$11:$C$1001,$E$15,$BP$11:$BP$1001,"1")
SUMIFS($BB$11:$BB$1001$C$11:$C$1001,$E$15,$H$11:$H$1001,G$31,$BH$11:$BH$1001,"Commercial Innovation")/1000
COUNTIFS(OFFSET($L$10,0,0,10000,1),$D65,OFFSET($AL$10,0,INDEX($AL$6:$AU$6,MATCH($D$59,$AL$10:$AU$10,0)),10000,1),">0",OFFSET($CI$10,0,0,10000,1),"Yes",OFFSET($D$10,0,0,10000,1),$E$15)
IFERROR(AVERAGEIFS($CJ:$CJ, $K:$K, "*",$L:$L,$D113,$D:$D,$E$15), "-")

you can use Calculate function for any conditional calculation in DAX.
There is no references and cells like excel in Power BI therefore there is no OFFSET or INDEX in Power BI but you can explain you problem in a table for find a solution instead of Offset and Index.
For another formulas that you want:
Excel Countifs:
COUNTIFS($K:$K,"*",$L:$L,E$31,$CS:$CS,1$D:$D,$E$15)
DAX:
Measure Name = Calculate(count(K_Column), tbl_name[k_Column]="*",
tbl_name[L_Column]=E31_Value,...)
Excel Sumifs:
SUMIFS($AU:$AU,$L:$L,E$31,$CI:$CI, "Yes",$D:$D,$E$15)/1000
DAX:
Measure Name = Calculate(Sum(AU), tbl_name[L_Column]=E31_Value,
tbl_name[CI_Column]="Yes",...)
and you have iferror in DAX like excel:
iferror(calculate(sum(column_name), filter1, filter2))
There is a filter function in DAX for create a filtered table We don't have something like that in Excel.

Related

Create a Power BI measure to sum a column where another column meets a requirement

I'm new to DAX and I'm trying to do something that would be really simple in Excel!
Using data from the same table, I'm trying to add a measure, that calculates my 'TargetCost' column where the 'NameUnit' is '1111'.
if nameunit = 1111 then sum the target cost
In excel the formula would be:
=sumif(nameunit,"1111",targetcost)
How do I write this into a measure in DAX please?
Here you go:
Measure =
CALCULATE(
SUM('Table'[targetcost]),
'Table'[nameunit] = "1111"
)
https://learn.microsoft.com/en-us/dax/calculate-function-dax

Power BI Dax Measure moving Sum by categories

im struggling with the following problem. I have categorical variables and and Amount column. What I want to do is, to write a dax measure which calculates the moving/rolling Sum, like you see in the third column "Dax Measure". Did not find any inhouse Dax function for that.
moving sum
EDIT:
Result Table with Dax Measure
Source Table
This will work if the category is always sorted ASC.
Dax measure =
VAR _currentRank = RANKX(ALL('Table'[Category]),CALCULATE(MIN('Table'[Category])),,ASC)
RETURN
CALCULATE(
CALCULATE(SUM('Table'[Amount]),TOPN(_currentRank,VALUES('Table'[Category]),MIN([Category]))),
ALL('Table'[Category])
)
Using RANKX to define the other and aggregating for all the item before it.

Power BI DAX subquery for multiple Tables - Complex DAX

I have 3 tables which I have mentioned in the below SQL Query, which I need to convert into a DAX formula which I'm not able to do as a newbie to Power BI, which similarly I need to do the same for almost 5 - 6 columns.
If this has figured out, I can do the remaining 5 DAX Calculated columns, which I need support on writing Complex DAX for below SQL
SELECT
Substr(TableA.Text_Noted,0,500)
FROM SYS_DATA_NODE_TAB TableA, SYS_DATA_NOTED TableC
WHERE TableA.ID_Name = TableC.ID_Name
AND TableA.task_note_text LIKE '%Field update Sender:%'
AND TableA.task_note_entered_date =
(
SELECT Max(TableB.task_note_entered_date)
FROM SYS_DATA_NODE_TAB TableB, SYS_DATA_NOTED TableC
WHERE TableB.task_note_text LIKE '%Field update Sender:%'
AND TableB.ID_Name = TableC.ID_Name )
AND rownum = 1 as Text_Noted;
Please support on this or help me guidance in writing this Complex DAX.
Thanks

Replace values in cell with DAX coding in Power bi

I have my data(file name - Data) which I have imported in power bi with a column named values
values
ext
int
safety_int
outside_training
gap_fill_int
so it is a large data, and it contains more than 2k categories , what I want is, to create a new column in power bi where blanks should be replaced with target_emp, and all other values(ext,int,gap_filling_int etc.) should be replaced with non_target_emp.
Please help me to do that in power bi.
In powerbi transform ->
Add Column:
if Text.Trim([category]) = "" then "target_emp" else "non_target_emp"
You could add a conditional column in the data model (sorry that I dont have an English screenshot for this):
Add column
Select conditional column
Add criteria to selection
#1 DAX
calculatedColumn= SWITCH(TRUE(), Data[Column1]=BLANK(),"target_emp", "non_target_emp")
#2 using PBI's binning
go to report view->click on the table->column name-> New Group

Creating an Index Column for a Descriptive Data Using “DAX” in Power BI

I have a table Like this,
Table1
I want to create a column called as Row Number using DAX and not Query Editor (M).
So the Expected output is,
This can be done in M - Power Query Side.
But, I am looking for a solution using DAX- Calculated Column.
Additional source data
The RANKX function should work fine for this purpose.
Row Number = RANKX ( Table1, Table1[ColA] )
Recommended reading:
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns