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)
)
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]
)
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
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-
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.