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
moumitadeb
Helper I
Helper I

Measure to find the value by latest date for a month

Hello Team,

 

I have a DAX table as below: (this data is calculated from a Base Table)

 

DATE_OF_EXTRACTIONSUMSTART_OF_MONTH
8/5/2024 0:003991.2338/1/2024 0:00
8/12/2024 0:003936.9068/1/2024 0:00
8/26/2024 0:003905.2228/1/2024 0:00
9/2/2024 0:003900.8219/1/2024 0:00
9/9/2024 0:003911.0589/1/2024 0:00
9/16/2024 0:003895.969/1/2024 0:00
9/30/2024 0:003898.859/1/2024 0:00
10/7/2024 0:003857.74810/1/2024 0:00
10/14/2024 0:003872.9110/1/2024 0:00
10/21/2024 0:003884.37410/1/2024 0:00
10/28/2024 0:003911.02210/1/2024 0:00

 

I have to create a measure to find the below output (find the last SUM value for each month) :

 

SUM
3905.222
3898.85
3911.022

 

Any help is appreciated !

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

@moumitadeb 

 

Download PBIX file with example below

 

Create a column in your table to indicate the last day in each month with an entry

 

LastDayInMonth = 

VAR _LastDate = CALCULATE(MAX('DataTable'[Date_of_Extraction]), ALLEXCEPT('DataTable', 'DataTable'[Start_of_Month]))

RETURN

    IF('DataTable'[Date_of_Extraction] = _LastDate, TRUE(), FALSE())

 

 

 

In a Table, add the Date_of_Extraction and Sum.  Add a filter using LastDayInMonth and set that to TRUE.

 

PhilipTreacy_0-1731368197994.png

 

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

6 REPLIES 6
v-zhengdxu-msft
Community Support
Community Support

Hi @moumitadeb 

 

Please try this measure:

MEASURE =
VAR _currentMonth =
    MONTH ( MAX ( 'Table'[DATE_OF_EXTRACTION] ) )
VAR _maxDate =
    CALCULATE (
        MAX ( 'Table'[DATE_OF_EXTRACTION] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            MONTH ( 'Table'[DATE_OF_EXTRACTION] ) = _currentMonth
        )
    )
RETURN
    IF ( MAX ( 'Table'[DATE_OF_EXTRACTION] ) = _maxDate, SUM ( 'Table'[SUM] ) )

The result is as follow:

vzhengdxumsft_0-1731393923432.png

 

 

Best Regards

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

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1731380879606.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FreemanZ
Super User
Super User

hi @moumitadeb 

 

try like:

measure =

VAR _start = MAX(data[START_OF_MON])

RETURN

MAXX(

    TOPN(

        1,

        FILTER(

           data,

           EOMONTH(data[DATE_OF_EXTRACTION], -1) + 1= _start

       ),

       data[DATE_OF_EXTRACTION]

    ),

   data[SUM]

)

PhilipTreacy
Super User
Super User

@moumitadeb 

 

Download PBIX file with example below

 

Create a column in your table to indicate the last day in each month with an entry

 

LastDayInMonth = 

VAR _LastDate = CALCULATE(MAX('DataTable'[Date_of_Extraction]), ALLEXCEPT('DataTable', 'DataTable'[Start_of_Month]))

RETURN

    IF('DataTable'[Date_of_Extraction] = _LastDate, TRUE(), FALSE())

 

 

 

In a Table, add the Date_of_Extraction and Sum.  Add a filter using LastDayInMonth and set that to TRUE.

 

PhilipTreacy_0-1731368197994.png

 

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks for your help. It worked .

Is this possible to achieve LastDayInMonth in power query and set a flag for TRUE/FALSE . I have a different scenario to achieve with same condition in Power Query.

Please guide !

Bibiano_Geraldo
Community Champion
Community Champion

Hi @moumitadeb ,

First, create a calculated column in your table to identify the last day for each month using this DAX:

IsLatestDayForMonth = 
VAR LastDateInMonth = 
    CALCULATE(
        MAX('YourTable'[DATE_OF_EXTRACTION]), 
        ALLEXCEPT('YourTable', 'YourTable'[START_OF_MONTH])
    )
RETURN 
    IF('YourTable'[DATE_OF_EXTRACTION] = LastDateInMonth, TRUE(), FALSE())

 

And then, create a measure using this DAX:

LastSUMForMonth = 
CALCULATE(
    SUM('YourTable'[SUM]),
    FILTER(
        'YourTable',
        'YourTable'[IsLatestDayForMonth] = TRUE()
    )
)

 

By the sample data you gave, the final result was 11 715,094:

Bibiano_Geraldo_0-1731364947786.png

 

I hope this help you, if yes, please give a kudo and mark the reply as solution

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.