Forum Discussion

CracktheCode85's avatar
2 years ago
Solved

Nested IF Statement in a Filtered Dates Calculation

Hello,   I'm using this formula to get the total sales for 2 business days ago. So if today is Business day 16, this formula is showcasing the Total sales for business Day 14.  However I want to ...
  • AmiraBedh's avatar
    2 years ago

    Try the follwing : 

     

    Total Sales Minus 2 Business Days = 
    VAR CurrentMaxDate = MAX('Dates'[Date])
    VAR TargetDate = CALCULATE(
        MAX('Dates'[Date]),
        FILTER(
            'Dates',
            'Dates'[Business Day] = 1 && 'Dates'[Date] < CurrentMaxDate
        ),
        ALL('Dates'), 
        TOPN(2, FILTER('Dates', 'Dates'[Business Day] = 1 && 'Dates'[Date] < CurrentMaxDate), 'Dates'[Date], DESC)
    )
    RETURN
    CALCULATE(
        SUM('Table'[Payment]),
        FILTER(
            'Dates',
            'Dates'[Date] = TargetDate
        )
    )
  • AmiraBedh's avatar
    AmiraBedh
    2 years ago

    Don't forget to accept your solution !