Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Syndicate_Admin
Administrator
Administrator

Create the relationship between 2 tables in the data model

Good afternoon

I have created a Calendar Table as follows:

Calendar =

where _cal = CALENDAR(MIN('Orders'[Start_Date]), MAX('Orders'[End_Date]))
return
ADDCOLUMNS(_cal,"Year", YEAR([Date]), "Month Num", MONTH([Date]), "Month Name", FORMAT([Date], "mmmm"))

RWRW_1-1655799467767.png

The orders table is as follows:

RWRW_0-1655799398985.png

I have created a DatePicker whose values are linked to the Calendar table where the user can select a range of dates between Start_Date and End_Date. The problem I am having is that I need to create the relationship between both tables because when I select the values in the DatePicker the selection is not made between the selected dates.

RWRW_2-1655799569417.png

How should I create the relationship in the model? I don't know how to relate the Date field to the order table with both Start_Date and End_date.

Thank you very much in advance

1 ACCEPTED SOLUTION

Hello

Troubleshoot the problem. In this measure of time in the AllSELECTED function you add all the columns that you are going to show in the report.

Time Measure =
WHERE SelectedTable =
FILTER (
ALLSELECTED ( Orders[Start Date], Orders[End Date],Orders[ID_BATCH],Orders[SIG_BY_ID] ),
Pmx[End Date] <> BLANK ()
)
WHERE CurrentStart = MAX ( Pmx[Start Date] )
WHERE PreviousDatesTable = FILTER ( SelectedTable, Pmx[Start Date] < CurrentStart )
WHERE PreviousEnd = MAXX ( PreviousDatesTable, Pmx[End Date] )
WHERE FirstSelectedDate = MINX ( PreviousDatesTable, Pmx[CPK_SIG_TIMESTAMP] )
WHERE TimeDifference = DATEDIFF ( PreviousEnd, CurrentStart, MINUTE )
WHERE Result = DIVIDE ( TimeDifference, 60, " " )
RETURN
Result
Thank you for the help you have given me, thank you very much

View solution in original post

10 REPLIES 10
Syndicate_Admin
Administrator
Administrator

As for this measure you told me to add

Measure = COUNTROWS ( FILTER ( Orders, Orders[Start_Date].[ Date] >= MIN ( 'Calendar'[Date] ) && Orders[End_Date]. [Date] <= MAX ( 'Calendar'[Date] ) ) )

I have it added on the screen on a Card on the screen and also in the table.

When the measure is active in the table, the number of rows I see is the same as the number it shows me on the Card.

RWRW_0-1656057318324.png

But when I turn off the measure in the table, I visually see fewer rows in the table and the same number in the Card. It takes away the one that is empty and that I should keep.

RWRW_1-1656057395919.png

Hi @Syndicate_Admin ,

 

Please try enabling the option "Show items with no data".

 

vkkfmsft_0-1656064093572.png

vkkfmsft_1-1656064112619.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Hello

I am not able to find that menu, where do I have to press please?

I've been clicking on the measure etc... and I don't see it

Thank you

Hello again

I was already able to find it and it works.

I am very happy, thank you very much.

Hello again

I have added some more columns to the order table and what is my surprise that the Time Measure is white in all rows.

RWRW_0-1656080463745.png

Any suggestions?

Hello

Troubleshoot the problem. In this measure of time in the AllSELECTED function you add all the columns that you are going to show in the report.

Time Measure =
WHERE SelectedTable =
FILTER (
ALLSELECTED ( Orders[Start Date], Orders[End Date],Orders[ID_BATCH],Orders[SIG_BY_ID] ),
Pmx[End Date] <> BLANK ()
)
WHERE CurrentStart = MAX ( Pmx[Start Date] )
WHERE PreviousDatesTable = FILTER ( SelectedTable, Pmx[Start Date] < CurrentStart )
WHERE PreviousEnd = MAXX ( PreviousDatesTable, Pmx[End Date] )
WHERE FirstSelectedDate = MINX ( PreviousDatesTable, Pmx[CPK_SIG_TIMESTAMP] )
WHERE TimeDifference = DATEDIFF ( PreviousEnd, CurrentStart, MINUTE )
WHERE Result = DIVIDE ( TimeDifference, 60, " " )
RETURN
Result
Thank you for the help you have given me, thank you very much

Hello again

I was already able to find it and it works.

I am very happy, thank you very much.

Syndicate_Admin
Administrator
Administrator

In case it is useful for you, here I leave the Calendar table as I have created it:

Calendar =
where _cal = CALENDAR(MIN('Pmx'[Start Date]), MAX('Pmx'[End Date]))
return
ADDCOLUMNS(_cal,"Year", YEAR([Date]), "Month Num", MONTH([Date]), "Month Name", FORMAT([Date], "mmmm"))
The calendar table is created with the minimum and maximum values of the Start Date and End Date fields, therefore the dates to be selected will always be in ranges that exist in the Orders table.

And this is the measure linked to the table that was simply to check that the records that are returned to me are with value 1, since the selected ranges are always going to be within date range.

InDateRange =
//Measure to know what rows are between dates selected by user
//0 - Not in range
//1 - In range
WHERE _rangeStart =
FIRSTDATE ( 'Calendar'[Date] )
WHERE _rangeEnd =
LASTDATE ( 'Calendar'[Date] )
RETURN
IF (
SELECTEDVALUE ( Pmx[Start Date] ) >= _rangeStart
&& SELECTEDVALUE ( Pmx[End Date] ) <= _rangeEnd
&& SELECTEDVALUE ( Pmx[End Date] ) <> BLANK(),
1,
0
)
v-kkf-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

Please try the measure and show items when it is not blank.

 

Measure = 
COUNTROWS (
    FILTER (
        Orders,
        Orders[Start_Date].[Date] >= MIN ( 'Calendar'[Date] )
            && Orders[End_Date].[Date] <= MAX ( 'Calendar'[Date] )
    )
)

vkkfmsft_1-1656051780257.png

vkkfmsft_0-1656051685334.png


If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

I have added the measure and the same thing continues to happen to me. If I have it active it comes out like this

RWRW_0-1656053247562.png

RWRW_1-1656053268926.png

RWRW_2-1656053295914.png

RWRW_4-1656053438749.png

And if I remove the measure now I lose the first and second row

RWRW_3-1656053424610.png

I need that when I deactivate the measure that I do not need to visualize in the table, the records of the Table continue to look as if there were

RWRW_5-1656053530274.png

Thank you and I look forward to it

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.