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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Maheshguptaz
Helper III
Helper III

need help with dax for sum of MAX month

Hi,

 

I've encountered an issue with a DAX query. I need to show the max month's numbers from the selected values. i.e
if I choose Jun, July and Aug, I should be able to see the sum of value for Aug alone and no other values from other months.

here's the dax I use:

Close Positions Select Month =
VAR _pos =
CALCULATE(
    SUM('Close Position Report'[NumberofPositions]),
    LASTDATE('Close Position Report'[LastDate_Month]),
    ALLEXCEPT('Close Position Report','Close Position Report'[Job Level]))
RETURN
maxx(
    VALUES('Shared DW_DimDate'[Date].[Month]),
    _pos)

I can see the total being calculated correctly, however, when I use a Matrix to represent the same I see values from July are being shown in the column total (please refer to SC below):
 
Maheshguptaz_0-1725015070005.png

This is the same case if I use any other column in the row.

Maheshguptaz_1-1725015195681.png

 

can anyone help me figure this out to omit the values from other months apart from the max of selected month?

regards,
Mahesh

1 ACCEPTED SOLUTION
v-xingshen-msft
Community Support
Community Support

Hi All,
Fisrtly dharmendars007 thank you for your solutions!
And @Maheshguptaz for your question, this is because in the matrix, there will be a specific calculation environment, in the total column if you can not determine the value of the month of August, they automatically display the value of the month closest to August, we just need to add a filter condition on this basis to complete your needs!

vxingshenmsft_1-1725246349428.png

 

_Close Positions Select Month = 
VAR _lastDate =SELECTEDVALUE(example_data[LastDate_Month],MAX('example_data'[LastDate_Month]))
VAR _pos =
   
   CALCULATE(SUM('example_data'[NumberofPositions]),'example_data'[LastDate_Month]=_lastDate)

VAR A=CALCULATE(MAX('example_data'[LastDate_Month]),ALLSELECTED('example_data'))
RETURN 
IF(ISINSCOPE('example_data'[Month]),
SUM('example_data'[NumberofPositions]),
IF(A=_lastDate,
_pos,
BLANK()
)
)

vxingshenmsft_0-1725246123565.png

Check out my pbix file if you still have questions, I'd be honoured if my answer solves your problem!
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

4 REPLIES 4
v-xingshen-msft
Community Support
Community Support

Hi All,
Fisrtly dharmendars007 thank you for your solutions!
And @Maheshguptaz for your question, this is because in the matrix, there will be a specific calculation environment, in the total column if you can not determine the value of the month of August, they automatically display the value of the month closest to August, we just need to add a filter condition on this basis to complete your needs!

vxingshenmsft_1-1725246349428.png

 

_Close Positions Select Month = 
VAR _lastDate =SELECTEDVALUE(example_data[LastDate_Month],MAX('example_data'[LastDate_Month]))
VAR _pos =
   
   CALCULATE(SUM('example_data'[NumberofPositions]),'example_data'[LastDate_Month]=_lastDate)

VAR A=CALCULATE(MAX('example_data'[LastDate_Month]),ALLSELECTED('example_data'))
RETURN 
IF(ISINSCOPE('example_data'[Month]),
SUM('example_data'[NumberofPositions]),
IF(A=_lastDate,
_pos,
BLANK()
)
)

vxingshenmsft_0-1725246123565.png

Check out my pbix file if you still have questions, I'd be honoured if my answer solves your problem!
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.

 

dharmendars007
Memorable Member
Memorable Member

Hello @Maheshguptaz , 

 

Please try the below measure and let us know if still it doesnt work..

 

Close Positions Select Month =
VAR LatestMonth =
MAXX(
VALUES('Shared DW_DimDate'[Date].[Month]),
'Shared DW_DimDate'[Date].[Month]
)

VAR Result =
CALCULATE(
SUM('Close Position Report'[NumberofPositions]),
FILTER(
ALLEXCEPT('Close Position Report', 'Close Position Report'[Job Level]),
'Close Position Report'[LastDate_Month] = LatestMonth
)
)

RETURN Result

If you find this helpful , please mark it as solution and Your Kudos are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

Hi @dharmendars007 ,

 

Thank you for your swift response. 

I've tried the DAX that you provided and it still gives the same output.

Regards,
Mahesh

Hi @Maheshguptaz ,

Has your problem been solved after all this time, or has a new problem arisen, if there are any other questions on this issue, feel free to contact me and I'll get back to you as soon as I receive the message.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.