Forum Discussion

Midway's avatar
Midway
Helper I
1 year ago
Solved

Help Modifying this DAX Formula

I have this formula, that someone here posted it in another thread, The below DAX formula defaults sales for current month and when other visual month is selected, it shows the correct sales for the...
  • tamerj1's avatar
    1 year ago

    Hi Midway 

    If both cost and sales are coming from the same table, then you need to remove the filter from the month slicer and any other column that is used as a sort by or a group by column. Even safer to remove tye filter from the date table completely. 

    var dt = eomonth( MAXX(summarize(Fact, DimDate[Date] ), dimdate[date]), 0)
    return
    CALCULATE(
    SUM(Fact[SALES]) - SUM(Fact[COST])
        DATESBETWEEN( DimDate[Date], EOMONTH( dt, -1) + 1, dt ),
    ALL ( DimDate )
    )
     
    but what I don't understand is the reason of not using the month directly in the formula like for example 
    CALCULATE(
    SUM(Fact[SALES]) - SUM(Fact[COST]),
    • DimDate[EndOfMonth] = MAX ( DimDate[EndOfMonth] )
    )