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
Anonymous
Not applicable

Join calendar table with 2 date between from my fact table SSAS

Hi

I would like to link a fact table with a start date and an end date with my calendar table. Power BI/SSAS does not allow to link a table using a between. My fact table includes only one element between the start date and the end date. The objective is to be able to display the active information between these 2 dates.

 

Table Calandar : 

DateYear WeekYear MonthYear QuarterYear
18/10/20152015-422015-102015-42015
19/10/20152015-422015-102015-42015
20/10/20152015-422015-102015-42015
21/10/20152015-422015-102015-42015
22/10/20152015-432015-102015-42015
…..…..…..…..…..
25/12/20202020-522020-122020-42020
26/12/20202020-522020-122020-42020
27/12/20202020-522020-122020-42020
28/12/20202020-522020-122020-42020
29/12/20202020-522020-122020-42020
30/12/20202020-532020-122020-42020
31/12/20202020-532020-122020-42020

 

Table Fact

 

Code ClientCode ElémentStart dateEnd dateAmount
100011912/11/201531/12/20162 000,00
100011901/01/201731/12/20172 012,20
100011901/01/2018 2 039,36
100012212/11/2015 63,00
100012201/07/201831/05/2020959,97
100012201/06/202031/07/2020678,70
100012201/08/202031/08/2020815,97
100012201/09/2020 959,97
100016401/07/201831/03/20194 617,06
100016401/04/201931/03/20204 660,10
100016401/04/202030/09/20204 670,35
100016401/10/202031/01/20210,00
100016401/02/2021 4 670,35
100017101/06/202030/09/20200,00
10001GB12/11/201501/09/202114 760,00
10001GB01/07/201810/04/202124 123,74

 

If i choose MonthYear=2020-10, the Amount will be the sum of : 2 039,36 + 63,00 + 959,97 + 0,00 + 4 670,35 + 14 760,00 + 24 123,74

 

With the sql, the relation between this 2 table will be :

 

( 'Date'>='Start date' and 'Date' <= 'End date' ) or 'End date' is null

I don't know how to achieve this relationship on the SSAS tabular/PowerBI model.

 

for more information, in my model the calendar table is linked to other fact tables.

 

Thanks You for reply.

 

Best Regards

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Don‘t create relationship between your date table and fact table,and you can create the following measure for visual level filter:

 

Measure = VAR a = MAX(Dim_Date[Date]) var b = MIN(Dim_Date[Date]) return IF(MAX('Table'[Start date])<=b&&(MAX('Table'[End date])>=a ||ISBLANK(MAX('Table'[End date]))),1,0)

 

Capture2.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

@v-deddai1-msft 

 

Hello,

I was not able to implement your solution because of the problem I raised in my previous message about using my model on other dimensions.
Do you have a solution to avoid Cartesian products?

Thank you for your feedback.

v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Don‘t create relationship between your date table and fact table,and you can create the following measure for visual level filter:

 

Measure = VAR a = MAX(Dim_Date[Date]) var b = MIN(Dim_Date[Date]) return IF(MAX('Table'[Start date])<=b&&(MAX('Table'[End date])>=a ||ISBLANK(MAX('Table'[End date]))),1,0)

 

Capture2.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Hello,
Sorry for my late answer.

Thank you very much for your reply.  I tried your solution by removing the relationship between the fact table and the time table.

However, I get Cartesian products when I use other dimensions that are related to my fact table.
It brings back all available periods between the fact table and the time table.
How can I delete the Cartesian products in order to indicate him to use the joints of the other dimensions related to the fact table?

 

abibane_1-1607033054761.png

 

 

When I use "billing element code" from the dim_eltfac table with a period and the measurement, I get a cartesian product.

 

Thanks

 

amitchandak
Super User
Super User

@Anonymous , I can date table do not have join with fact table

measure =
var _min =minx(allselected(date),date[date])
var _max =maxx(allselected(date),date[date])
return
calculate(Sum(Table[Amount]), filter(Table, Table[Start Date] <=_max && (isblank(Table[End Date]) || Table[End Date] >=_min)))

 

If have join with start date

measure =
var _min =minx(allselected(date),date[date])
var _max =maxx(allselected(date),date[date])
return
calculate(Sum(Table[Amount]), filter(Table, Table[Start Date] <=_max && (isblank(Table[End Date]) || Table[End Date] >=_min)))

 

measure =
var _min =minx(allselected(date),date[date])
var _max =maxx(allselected(date),date[date])
return
calculate(Sum(Table[Amount]), filter(Table, Table[Start Date] <=_max && (isblank(Table[End Date]) || Table[End Date] >=_min)), crossfilter(Table[Start Date],date[date], none))

Anonymous
Not applicable

Hi

 

Thanks you for you reply. I try add this 3 messure but have not right result ;(

For now i have made the relation with "Start Date" between the fact table et date table

When I filter YearMonth 2020-10 (in my date table), i have only the element where Start Date is equals 2020-10. But I would like all the element actif 

I have just 

 

Code ClientCode ElementStart dateEnd dateAmount
100016401/10/202031/01/20210

 

 

But I would like this résult : 

 

Code ClientCode ElémentStart dateEnd dateAmount
100011901/01/2018 2 039,36
100012212/11/2015 63
100012201/09/2020 959,97
100016401/10/202031/01/20210
100016401/02/2021 4 670,35
10001GB12/11/201501/09/202114 760,00
10001GB01/07/201810/04/202124 123,74

 

because the analysis date '2010-10' is between start date and end date

 

How to model and realize the joint to get this result?

 

Thanks You for the reply

 

Best Regards,

Amine

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.