Forum Discussion

Mkrishna's avatar
Mkrishna
Helper III
2 years ago
Solved

Context Transitioning not working /Code not working

Hi All,   I am new to PBI and this is my data model My goal is to caculate as follows  1. If user select date December 2023 then the code should first find the common store in Fact table ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Mkrishna ,

     

    Then you could try EDATE() function. The function returns the date that is the indicated number of months before or after the start date. 

    Modified:

    Sales Amount =
    VAR _Reference_Date =
        MAX ( 'Date'[Date] )
    VAR Customers =
        VALUES ( 'Store List'[Store Number] )
    VAR PriorCustomers =
        CALCULATETABLE (
            VALUES ( 'Fact Table'[Store Number] ),
            FILTER (
                ALL ( 'Date' ),
                'Date'[Date] >= EDATE ( _Reference_Date, 3 )
                    && 'Date'[Date] <= _Reference_Date
            )
        )
    VAR CommonCustomers =
        INTERSECT ( Customers, PriorCustomers )
    VAR Sales =
        CALCULATE (
            SUM ( 'Fact Table'[Sales] ),
            FILTER (
                ALL ( 'Fact Table' ),
                'Fact Table'[Store Number]
                    IN CommonCustomers
                        && 'Fact Table'[Visit Date] >= EDATE ( _Reference_Date, 3 )
                        && 'Fact Table'[Visit Date] <= _Reference_Date
            )
        )
    RETURN
        Sales
    

     

    Best Regards,

    Stephen Tao

     

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