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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Measure to extract month

Hello Community,

 

I am connected to a live dataset where I can't create calculated columns or go to the power query, I have a column date and I want to extract the month/Year from it. 

Is there any possibilty to create measure to extract this ?

 

Thanks in advance

 

10 REPLIES 10
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

As measure calculated by the context, in the formula, the context is date, if you put date in the visual, the formula will return the current date in the same row, if you don't put date in the visual, the formula will return the max date in the table.

My solution is put date in the visual, and create another measure to sum the value.

SUM =
SUMX (
    FILTER (
        ALL ( 'Table' ),
        YEAR ( 'Table'[Date] ) = YEAR ( MAX ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( MAX ( 'Table'[Date] ) )
    ),
    'Table'[Value]
)

Get the correct result.

vkalyjmsft_1-1645690250117.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

Anonymous
Not applicable

Hello @v-yanjiang-msft 

 

Thanks for your effort. Unfortenatly this is not the expected result, I made some modification on your pbix

file, I added a number column and another date in 2020,

malekzouaridk_0-1645691496934.png

 

what I want to display is a table showing the sum of value per number and date for example:

Number        Date             SUM

1002             FEB 2020      55

1002             FEB 2022      15

1003             FEB 2020      40

1003             FEB 2022      20

 

I hope I was clear 

 

Thanks in advance 🙂

          

Hi @Anonymous ,

Does your expected result based on the data in the screen shot? In your screen shot, in my understanding, you want to get:

Num   Date          Sum

1002   2022-01        6

1003   2022-02        15

1002   2020-01        11

1003   2020-01        15

vkalyjmsft_0-1645692406630.png

Best Regards,
Community Support Team _ kalyj

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

Anonymous
Not applicable

Sorry @v-yanjiang-msft , but the measure didn't work because it's direct query 😞

Hi @Anonymous ,

I modify the formula based on your sample data, you can have a try.

SUM =
SUMX (
    FILTER (
        ALL ( 'Table' ),
        YEAR ( 'Table'[Date] ) = YEAR ( MAX ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( MAX ( 'Table'[Date] ) )
            && 'Table'[Number] = MAX ( 'Table'[Number] )
    ),
    'Table'[Value]
)

Get the result.

vkalyjmsft_0-1645759882779.png

I attach the sample below for reference.

Best Regards,
Community Support Team _ kalyj

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

 

 

Anonymous
Not applicable

Hello @v-yanjiang-msft , 

 

My report is on direct query, it doesn't accept SUMX 

malekzouaridk_0-1645777785072.pngmalekzouaridk_1-1645777805793.png

 

Anonymous
Not applicable

@Fowmy Thanks for you help, I have 3 columns raw material number, Quantity and date, I want when selecting these 3 columns on a table, see the sum of quantity per material number per date for example:

malekzouaridk_0-1645521438892.png

I have this data, I want the sum of quantity for 1002 on february, mars...

 

 

Fowmy
Super User
Super User

@Anonymous 

You can use a measure to extract the Month Year as follows:

MonthYear = format( MAX('Date'[Date]) , "Mmm yyyy")

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Thanks for you response, but when I add a calculation with this measure it takes always the latest month as seen here :

malekzouaridk_0-1645435097932.png

 

 

@Anonymous 

May I know, based on the screenshot above, what your expected result for Month and Year ? 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.