Power BI DAX subquery for multiple Tables - Complex DAX - powerbi

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

Related

Power BI Min date of each category

I am familiar with SQL and I can write a query to return results of a query to Select MIN(Date), MAX(Date), SUM(quality) and GROUP BY. However, I am new to Power BI and DAX and find it difficult to do the same on Power BI. Below is my situation.
These tables on Power BI:
Dim_ManefactureDate
Dim_ReleaseDate
Fact_OrderID
Table Relationships
Adding a table visualization to a new page to show data from three tables above, data is showing as below:
Under Values of Visualizations, when selecting SUM over Netweight, it automatically summarizes expected Netweight. However, for ManufactureDate and ReleaseDate, when selecting Earliest then Power BI table shows unexpected 1/01/1900 values like this:
I expect earliest date of each OrderID as below:
I have also tried to use a DAX function to create a new column but it gets error
ManufactureDate_Earliest =
VAR Sum_Netweight = SUM(Fact_OrderID[NetWeight])
VAR GroupBy_OrderID = GROUPBY(Fact_OrderID,Fact_OrderID[OrderID])
RETURN
CALCULATE(
MIN(RELATED(Dim_ManufactureDate[DateBK]))
)
Thank you very much for your help
Due to getting values from relationship tables, used these measured and solved the issue
ManufactureDate_Earliest =
CALCULATE(
MIN(ManufactureDate[DateBK]),
CROSSFILTER(Fact_Order[ManufactureDate_DateSK], ManufactureDate[DateSK], BOTH)
)
ReleaseDate_Earliest =
CALCULATE(
MIN(ReleaseDate[DateBK]),
CROSSFILTER(Fact_Order[ReleaseDate_DateSK], ReleaseDate[DateSK], BOTH)
)

Power BI - If a date is between 2 dates using relationships

I am trying to determine if a date is between 2 other dates that are is 2 different tables using
Power BI.
For simplicity, here is the model that I have :
TableB is the bridge table between TableA and TableC.
I have an inactive relationship between tableA and TableC.
I have tried the following logic to check if TableC.createdDate is between TableA.startDate and TableA.endDate :
Create a calculated column in TableC, but I was not able to access columns in TableA
Create a calculated column in TableB, but I was having blank results, which is not suppose to happen
Have you tried using USERELATIONSHIP to force your calculated column to use the inactive relationship to TableA? documentation link
So something like
CALCULATE(
{{created date is >start and <end}},
USERELATIONSHIP('TableA'[TableB_ID],'TableC'[TableB_ID]
)

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

Power BI - Select Slicer Date Between 2 Columns

Hopefully a quick explanation of what I am hoping to accomplish followed by the approach we've been working on for over a year.
Desired Result
I have a table of SCD values with two columns, SCD_Valid_From and SCD_Valid_To. Is there a way to join a date table in my model (or simply use a slicer without a join) in order to be able to choose a specific date that is in between the two SCD columns and have that row of data returned?
Original Table
ID | SCD_Valid_From | SCR_Valid_To | Cost
1 2020-08-01 2020-08-03 5.00
Slicer date chosen is 2020-08-02. I would like this ID=1 record to be returned.
What We've Attempted So Far
We had a consultant come in and help us get Power BI launched last year. His solution was to create an expansion table that would contain a row for every ID/Date combination.
Expanded Original Table
ID | SCD_Valid_Date | Cost
1 2020-08-01 5.00
1 2020-08-02 5.00
1 2020-08-03 5.00
This was happening originally on the Power BI side, and we would use incremental refresh to control how much of this table was getting pushed each day. Long story short, this was extremely inefficient and made the refresh too slow to be effective - for 5 years' worth of data, we would need over 2000 rows per ID just to be able to select a dimensional record.
Is there a way to use a slicer where Power BI can select the records where that selected date falls between dates in two columns of a table?
Let me explain a workaround and I hope this will help you to solve your issue. Let me guess you have below 2 tables-
"Dates" table with column "Date" from where you are generating the date slicer.
"your_main_table" with with column "scd_valid_from" and "scd_valid_to".
Step-1: If you do not have relation between table "Dates" and "your_main_table", this is fine as other wise you have to create a new table like "Dates2". For this work around, you can not have relation between those tables.
In case you have already relation established between those tables, create a new custom table with this below code-
Dates2 =
SELECTCOLUMNS(
Dates,
"Date", Dates[Date]
)
From here, I will consider "Dates2" as source of your Date slicer. But if you have "Date" table with no relation with table "your_main_table", just consider "Dates" in place of "Dates2" in below measures creation. Now, Create these following 4 measures in your table "your_main_table"
1.
date_from_current_row = max(join_using_date_range[SCD_Valid_From])
2.
date_to_current_row = max(join_using_date_range[SCD_Valid_to])
3.
date_selected_in_slicer = SELECTEDVALUE(Dates2[Date])
4.
show_hide_row =
if(
[date_selected_in_slicer] >= [date_from_current_row]
&& [date_selected_in_slicer] <= [date_to_current_row]
,
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "your_main_table"
Final Step: Now just add a visual level filter with the measure "show_hide_row" and set value will show only when "show_hide_row = 1".
The final output will be something like below image-

How do I convert Excel to DAX Formula?

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.