Forum Discussion

cv02011's avatar
cv02011
New Member
6 years ago

fact table startdate -enddate

I have a slowly changing dimension and a Fact Table

ProductCategoryStartDateEndDate
P1C101/01/202020/01/2020
P1C221/01/202031/03/2020
P2C301/01/202031/12/2099

 

ProductSalesDate
P110031/01/2020
P115029/02/2020
P130031/03/2020
P250031/01/2020

 

I'm interested in seeing for a selected date ( in the second table I have only the end of month) the number of products for each category and the sales from the second table.

For example if I choose 31/01/2020 I want to see only Category C2 - sales 100 and Category C3- sales 500 (1 product each).

 

How can I manage StartDate-EndDate in the first table and assign the correct category for every product of the second table?

Thank you

4 Replies

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi  cv02011 

    You could create a measure as below:

    Measure =
    CALCULATE (
        MAX ( Table1[Category] ),
        FILTER (
            Table1,
            Table1[Product] = SELECTEDVALUE ( Table2[Product] )
                && SELECTEDVALUE ( Table2[Date] ) >= Table1[StartDate]
                && SELECTEDVALUE ( Table2[Date] ) <= Table1[EndDate]
        )
    )

    Result:

    and here is sample pbix file, please try it.

     

    Regards,

    Lin

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion
    Well, with the sample data, you would do this:

    Table2 Category = MAXX(FILTER('Table1'[Product] = 'Table2'[Product] && 'Table2'[Date]>='Table1'[StartDate] && 'Table2'[Date]<='Table1'[EndDate]),[Category])