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

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

Related

Power BI - Get the Days of current Month

I have a column "Days of Month" which is just rows from 1 to 31 and a filter above with the date as you can see in the screenshot below. I want to filter this column to show me the days of each month based on the filter above.
For example if the date above is 2/2/2020 i would like to see 28 rows on my column.
I tried several solutions but i couldn't achieve this.
Can anyone help me ?
I was able to get this working by duplicating the date table and creating a relationship to its duplicate on year and month.
Add a [YearMonth] column to your date table
Duplicate the Dates table as Dates2
Create a many-to-many data relationship between Dates and Dates2 on the [YearMonth] column. Set the cross filter direction to Single (Dates filters Dates2)
Set up your report to use a slicer or filter on Dates[Date] and display Date2[Day] in a table visual. Here is the result:

Power BI Slicer on one table not fitering joined table

My relationship between two tables looks like this:
I use a single select slicer that filters the table [ExhibitorClass_Details]. But it is not filtering the joined table [EventMax_Details]:
Why does my slicer not filter the joined table, what am I missing?
How can I make the slicer filter both tables?
The Solution was to go under Manage Relationships and set up the "cross filter direktion":
Result:

Power Bi Extract a Column value based on some another field in different Table

I have a Power BI table with some columns as given below:
Table1 - Columns(Project, Program, Name, Attribute, ID)
Example of table1:
Now I have a different measure which is used to view Power BI report. It also has some fields as given below:
Measure1 - Columns(Project, Name, Attribute, and few more)
Example of Measure:
Now I want to add ID (which is available in Table1) as Measure1 is being used to view report. How can I display ID based upon Name and Project.
Can anyone guide or help how to solve it?
If you can do this in your source Database using left join between this 2 tables.
If not, then you can use virtual relationship in DAX:
Display_ID = CALCULATE(min(Table1[ID]), TREATAS(VALUES(Table1[Project]), Measure1[Project]), TREATAS(VALUES(Table1[Name]), Measure1[Name]))

Power BI - Filter table using slicer to match within concatenated column

I've looked all over and can't find a way to do this.
In the table, I have all postcodes throughout the UK and a calculated column that concatenates from another table the products' that have been purchased in that location.
I need to filter the table to hide rows where the value selected in the slicer is in the concatenated column. I think this needs to be a measure and have tried using CONTAINSSTRING but nothing seems to be working.
Latest measure that I have tried is:
=IF(CONTAINSSTRING([Concatenated Values],[Selected Slicer Value]),"Hide","Show")
Does anyone have any ideas?
Example tables and expected results:
You can link the "another table" (the one with the products (not concatenated) per area) to the Area table.
Just change the filter option to: cross-filter direction: both
Then you can use it in your slicer.
Follow these below steps to achieve your requirement.
Let-
Your Slicer Table name: Table1
Your Details table name: Table2
Step-1: Create this following measure in Table2
show_hide_this_row =
FIND(
SELECTEDVALUE(Table1[products]),
MIN(Table2[products]),
,
0
)
Step-2: Add visual level filter using measure "show_hide_this_row" as below-
The output will be as below-
This functionality only works perfect when single selection is enabled in your slicer.

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-