Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Midway
Helper I
Helper I

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 selected month; this measure is showing in a card visual;

var dt = eomonth( MAXX(summarize(FactSageProject, DimDate[Date] ), dimdate[date]), 0)
return
CALCULATE(
SUM(FacttSALES]),
    DATESBETWEEN( DimDate[Date], EOMONTH( dt, -1) + 1, dt )
)
This works really well to calculate a single field from the fact table.
 
Now, I'm trying to modify it to get the margin from the same fact, the other field in the fact is COST.
Trying to modify like below;
 
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 )
)

by default it shows the correct margin for the current month (Card visual), when selecting current month, it shows number correctly as well but when selecting other month,  the number shows a zero or blank.
How can I make this work so it calculates margins for the rest of the selected months?

 

Thanks in advance for your help!

 

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

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] )
)

View solution in original post

2 REPLIES 2
tamerj1
Community Champion
Community Champion

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] )
)

hi tamerj1,

that worked! thanks so much!

 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.