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
lavdeepk
Resolver I
Resolver I

Need help with same period last year's Dax measure calculation

Hi All,

 

I am straggling with the same period last year's Dax measure calculation.

 

I have created a measure for MTD calculation which is working fine for me. (MTD from 01st Dec’21 to 19th Dec’21.) MTD:=CALCULATE(SUM([Selling_Price_INR]),DATESMTD(Table1[Date])

 

I want to calculate the sum of the “Selling_Price_INR” same period last year which should be this period (PYMTD from 01st Dec’20 to 19th Dec’20.). I have created the below formula for this.

 

PYMTD:=CALCULATE([MTD], SAMEPERIODLASTYEAR(Table1[Date]))  --- This Dax formula giving result full month dates (01st Dec’20 to 31st Dec’20 )of last year but I want to total sum only this period 01st Dec’20 to 19th Dec’20

 

Please help me this how I can calculate sum last year same period which is 01st Dec’20 to 19th Dec’20

 

 

DateSelling_Price_INR

2020-12-01 0.002255246.77
2020-12-02 0.003096234.74
2020-12-03 0.003236250.19
2020-12-04 0.007366312.97
2020-12-05 0.005554695.47
2020-12-06 0.001178403.87
2020-12-07 0.0017437223.27
2020-12-08 0.0013299216.78
2020-12-09 0.0013709546.96
2020-12-10 0.0020120600.75
2020-12-11 0.0013942309.06
2020-12-12 0.002866834.54
2020-12-13 0.00699437.12
2020-12-14 0.0030780634.22
2020-12-15 0.0047665480.07
2020-12-16 0.0026201028.25
2020-12-17 0.0026220188.95
2020-12-18 0.0067693154.26
2020-12-19 0.005476854.24
2020-12-20 0.001747140.633
2020-12-21 0.0029443613.86
2020-12-22 0.0026789594.91
2020-12-23 0.0043023377.41
2020-12-24 0.0055135192.8
2020-12-25 0.002855744.193
2020-12-26 0.0013919878.81
2020-12-27 0.001399933.66
2020-12-28 0.0074456127.84
2020-12-29 0.00110314082.7
2020-12-30 0.0072655257.12
2020-12-31 0.00158815551.4
2021-12-01 0.006563231.36
2021-12-02 0.007157552.26
2021-12-03 0.0013310600.24
2021-12-04 0.002871327.66
2021-12-05 0.00368188.25
2021-12-06 0.0033300654.12
2021-12-07 0.0028439129.76
2021-12-08 0.0042354641.24
2021-12-09 0.0044812384.46
2021-12-10 0.0028299850.56
2021-12-11 0.004321508.66
2021-12-12 0.001004433.13
2021-12-13 0.0057838953.02
2021-12-14 0.0052555825.2
2021-12-15 0.0059459761.97
2021-12-16 0.0070941469.57
2021-12-17 0.00101399070.6
2021-12-18 0.002703877.94
2021-12-19 0.0012914817.52

Thanks 

Lavdeep

 

1 ACCEPTED SOLUTION

Hi @lavdeepk ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a measure as below to get the sum of selling price

Selling prices = SUM([Selling_Price_INR])

2. Create a measure as below to get the selling prices in the same period of previous year

Selling for same period in previous year = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Table1'[Date] ), ALL ( 'Table1' ) )
VAR _pydate =
    EDATE ( _maxdate, -12 )
RETURN
    CALCULATE (
        [Selling prices],
        SAMEPERIODLASTYEAR ( 'Table1'[Date] ),
        FILTER ( ALLSELECTED ( 'Table1' ), 'Table1'[Date] <= _pydate )
    )

yingyinr_0-1640315649587.png

In addition, you can refer the following blogs to get it.

Previous year up to a certain date

Same Period Last Year to Date DAX Calculation in Power BI

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
amitchandak
Super User
Super User

@lavdeepk , first all for time intelligence use a date table marked as date table

 

You can try measures like

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
Previous year Month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth(dateadd('Date'[Date],-11,MONTH)))

 

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

Why Time Intelligence Fails - Power bi 5 Savior Steps for TI: https://youtu.be/OBf0rjpp5Hw

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak,

 

I have marked my date table as a date table.

 

I try to apply the given above Dax formula to calculate last year's MTD Sales. This is not giving results as desired instead of this period  PYMTD from 01st Dec’20 to 19th Dec’20.) giving full month sales number 

 

lavdeepk_1-1640002988275.png

 

 

Hi @lavdeepk ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a measure as below to get the sum of selling price

Selling prices = SUM([Selling_Price_INR])

2. Create a measure as below to get the selling prices in the same period of previous year

Selling for same period in previous year = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Table1'[Date] ), ALL ( 'Table1' ) )
VAR _pydate =
    EDATE ( _maxdate, -12 )
RETURN
    CALCULATE (
        [Selling prices],
        SAMEPERIODLASTYEAR ( 'Table1'[Date] ),
        FILTER ( ALLSELECTED ( 'Table1' ), 'Table1'[Date] <= _pydate )
    )

yingyinr_0-1640315649587.png

In addition, you can refer the following blogs to get it.

Previous year up to a certain date

Same Period Last Year to Date DAX Calculation in Power BI

Best Regards

Community Support Team _ Rena
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!

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.

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.