Forum Discussion

Excellove15's avatar
Excellove15
Iron Contributor
Sep 23, 2024

Create relationship between calendar and fact using Date range

Hi Team,   I have two tables as below:     The fact table has date range in a imbalanced way as below:   For example, row 1 and 2 contains full days in a month(April & May). But f...
  • SergeiBaklan's avatar
    SergeiBaklan
    Sep 24, 2024

    Excellove15 

    For such table

    measure for number of days could be

    Number of Dates = 
    VAR minDate = MIN( 'Date'[Date] )
    VAR maxDate = MAX( 'Date'[Date] )
    RETURN
        SUMX(
            Source,
            IF(
                Source[Date To] < minDate || Source[Date From] > maxDate,
                BLANK( ),
                INT( MIN( Source[Date To], maxDate ) - MAX( Source[Date From], minDate ) ) + 1
            )
        )

    which gives

    or

    No relationships between Date and Source

    Didn't catch how you calculate average cost, so ignored that.

Resources