cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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.00 2.25525e+06 2020-12-02 0.00 3.09623e+06 2020-12-03 0.00 3.23625e+06 2020-12-04 0.00 7.36631e+06 2020-12-05 0.00 5.5547e+06 2020-12-06 0.00 1.1784e+06 2020-12-07 0.00 1.74372e+07 2020-12-08 0.00 1.32992e+07 2020-12-09 0.00 1.37095e+07 2020-12-10 0.00 2.01206e+07 2020-12-11 0.00 1.39423e+07 2020-12-12 0.00 2.86683e+06 2020-12-13 0.00 699437 2020-12-14 0.00 3.07806e+07 2020-12-15 0.00 4.76655e+07 2020-12-16 0.00 2.6201e+07 2020-12-17 0.00 2.62202e+07 2020-12-18 0.00 6.76932e+07 2020-12-19 0.00 5.47685e+06 2020-12-20 0.00 1.74714e+06 2020-12-21 0.00 2.94436e+07 2020-12-22 0.00 2.67896e+07 2020-12-23 0.00 4.30234e+07 2020-12-24 0.00 5.51352e+07 2020-12-25 0.00 2.85574e+06 2020-12-26 0.00 1.39199e+07 2020-12-27 0.00 1.39993e+06 2020-12-28 0.00 7.44561e+07 2020-12-29 0.00 1.10314e+08 2020-12-30 0.00 7.26553e+07 2020-12-31 0.00 1.58816e+08 2021-12-01 0.00 6.56323e+06 2021-12-02 0.00 7.15755e+06 2021-12-03 0.00 1.33106e+07 2021-12-04 0.00 2.87133e+06 2021-12-05 0.00 368188 2021-12-06 0.00 3.33007e+07 2021-12-07 0.00 2.84391e+07 2021-12-08 0.00 4.23546e+07 2021-12-09 0.00 4.48124e+07 2021-12-10 0.00 2.82999e+07 2021-12-11 0.00 4.32151e+06 2021-12-12 0.00 1.00443e+06 2021-12-13 0.00 5.7839e+07 2021-12-14 0.00 5.25558e+07 2021-12-15 0.00 5.94598e+07 2021-12-16 0.00 7.09415e+07 2021-12-17 0.00 1.01399e+08 2021-12-18 0.00 2.70388e+06 2021-12-19 0.00 1.29148e+07

Thanks

Lavdeep

1 ACCEPTED SOLUTION
Community Support

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 )
)``````

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.
3 REPLIES 3
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

Resolver I

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

Community Support

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 )
)``````

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.

Announcements

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors