Forum Discussion

chrisyan_manalu's avatar
3 months ago
Solved

Dynamic Calculation Different Period

Hi everyone, I'm facing a Power BI/DAX issue and would appreciate any suggestions. Data Model I have: FactSales (transaction table) DimDateTable1 (Date table for Period A) DimDateTable2 (Date ...
  • v-kathullac's avatar
    3 months ago

    Thankyou powerbidev123   for Addressing the issue.


    Hi chrisyan_manalu ,

     

    Thank you for reaching out to Microsoft Fabric Community Forum,Below are the dax measure you can try to resolve your issue.

    Using two separate date tables is the correct design if the requirement is to compare two completely independent date selections. However, the issue occurs because when YtdFinal is evaluated in a visual filtered by Period B, the filter context from DimDateTable2 propagates to the fact table, and your YtdNet measure is no longer isolated to Period A. The solution is to make each measure explicitly control which date table affects the fact table.

    YtdNet =
    VAR SelectedDates =
        VALUES ( DimDateTable1[Date] )
    
    RETURN
    CALCULATE (
        [NetMeasure],
        REMOVEFILTERS ( DimDateTable2 ),
        TREATAS (
            SelectedDates,
            FactSales[Date]
        )
    )

     

    YtdSalesSQL =
    VAR SelectedDates =
        VALUES ( DimDateTable2[Date] )
    
    RETURN
    CALCULATE (
        [SalesSQL],
        REMOVEFILTERS ( DimDateTable1 ),
        TREATAS (
            SelectedDates,
            FactSales[Date]
        )
    )
    YtdSalesPostgre =
    VAR SelectedDates =
        VALUES ( DimDateTable2[Date] )
    
    RETURN
    CALCULATE (
        [SalesPostgre],
        REMOVEFILTERS ( DimDateTable1 ),
        TREATAS (
            SelectedDates,
            FactSales[Date]
        )
    )
    YtdFinal =
    [YtdNet]
    +
    [YtdSalesSQL]
    +
    [YtdSalesPostgre]

     

    Thanks & Regards,

    Chaithanya.