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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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