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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Maahmohammed
Helper I
Helper I

How to calculate MTD GM%

Dears, 

I have used the code below in developing MTD for Sales:

 

Sales_ADS-MTD =
VAR _Date = today()
VAR _Max_Date = Max('1_Calendar'[0_Date])
VAR _Compared_Date = Min(Date(Year(_Max_Date),Month(_Max_Date),Day(_date)),_Max_Date)
Return
Calculate(
          AVERAGEX(DATESMTD(
                               CALCULATETABLE(
                                               VALUES('1_Calendar'[0_Date]),
                                                KEEPFILTERS('1_Calendar'[0_Date]<=_Compared_Date)
                                             )
                             ),
                             '0_Measures_Sales'[0_Sales_5_Total]
                   )
But as you know, in case of GM%, we couldn't calculate the average of %, so, how to calculate the MTD GM% MTD?
Regards
         )
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Maahmohammed ,

If you want to calculate GM%, you can calculate it by dividing the cumulative gross profit by the cumulative sales, here is the DAX I wrote I hope it helps.

GM_MTD = 
VAR D=MAX('Table'[Date])
VAR F=DATE(YEAR(D),MONTH(D),1)
VAR B=MIN(DATE(YEAR(D),MONTH(D),DAY(TODAY())),D)
VAR cumulativeprofit=
   CALCULATE(
       SUM('Table'[Gross_Margin]), 
      FILTER(ALL('Table'),
    'Table'[Date]>=F&&'Table'[Date]<=B))
VAR Cumulativesales= CALCULATE(
       SUM('Table'[Sales_5_Total]),
       FILTER(ALL('Table'),
       'Table'[Date]>=F&&'Table'[Date]<=B
       )
)

RETURN
DIVIDE(cumulativeprofit,Cumulativesales,0)

vxingshenmsft_0-1724293896345.png

If you have any other questions, check out the pbix file I've uploaded, I'd be incredibly proud to help you out!

Hope it helps!

Best regards,
Community Support Team_ Tom Shen

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Maahmohammed ,

If you want to calculate GM%, you can calculate it by dividing the cumulative gross profit by the cumulative sales, here is the DAX I wrote I hope it helps.

GM_MTD = 
VAR D=MAX('Table'[Date])
VAR F=DATE(YEAR(D),MONTH(D),1)
VAR B=MIN(DATE(YEAR(D),MONTH(D),DAY(TODAY())),D)
VAR cumulativeprofit=
   CALCULATE(
       SUM('Table'[Gross_Margin]), 
      FILTER(ALL('Table'),
    'Table'[Date]>=F&&'Table'[Date]<=B))
VAR Cumulativesales= CALCULATE(
       SUM('Table'[Sales_5_Total]),
       FILTER(ALL('Table'),
       'Table'[Date]>=F&&'Table'[Date]<=B
       )
)

RETURN
DIVIDE(cumulativeprofit,Cumulativesales,0)

vxingshenmsft_0-1724293896345.png

If you have any other questions, check out the pbix file I've uploaded, I'd be incredibly proud to help you out!

Hope it helps!

Best regards,
Community Support Team_ Tom Shen

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors