Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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 | 2255246.77 |
2020-12-02 0.00 | 3096234.74 |
2020-12-03 0.00 | 3236250.19 |
2020-12-04 0.00 | 7366312.97 |
2020-12-05 0.00 | 5554695.47 |
2020-12-06 0.00 | 1178403.87 |
2020-12-07 0.00 | 17437223.27 |
2020-12-08 0.00 | 13299216.78 |
2020-12-09 0.00 | 13709546.96 |
2020-12-10 0.00 | 20120600.75 |
2020-12-11 0.00 | 13942309.06 |
2020-12-12 0.00 | 2866834.54 |
2020-12-13 0.00 | 699437.12 |
2020-12-14 0.00 | 30780634.22 |
2020-12-15 0.00 | 47665480.07 |
2020-12-16 0.00 | 26201028.25 |
2020-12-17 0.00 | 26220188.95 |
2020-12-18 0.00 | 67693154.26 |
2020-12-19 0.00 | 5476854.24 |
2020-12-20 0.00 | 1747140.633 |
2020-12-21 0.00 | 29443613.86 |
2020-12-22 0.00 | 26789594.91 |
2020-12-23 0.00 | 43023377.41 |
2020-12-24 0.00 | 55135192.8 |
2020-12-25 0.00 | 2855744.193 |
2020-12-26 0.00 | 13919878.81 |
2020-12-27 0.00 | 1399933.66 |
2020-12-28 0.00 | 74456127.84 |
2020-12-29 0.00 | 110314082.7 |
2020-12-30 0.00 | 72655257.12 |
2020-12-31 0.00 | 158815551.4 |
2021-12-01 0.00 | 6563231.36 |
2021-12-02 0.00 | 7157552.26 |
2021-12-03 0.00 | 13310600.24 |
2021-12-04 0.00 | 2871327.66 |
2021-12-05 0.00 | 368188.25 |
2021-12-06 0.00 | 33300654.12 |
2021-12-07 0.00 | 28439129.76 |
2021-12-08 0.00 | 42354641.24 |
2021-12-09 0.00 | 44812384.46 |
2021-12-10 0.00 | 28299850.56 |
2021-12-11 0.00 | 4321508.66 |
2021-12-12 0.00 | 1004433.13 |
2021-12-13 0.00 | 57838953.02 |
2021-12-14 0.00 | 52555825.2 |
2021-12-15 0.00 | 59459761.97 |
2021-12-16 0.00 | 70941469.57 |
2021-12-17 0.00 | 101399070.6 |
2021-12-18 0.00 | 2703877.94 |
2021-12-19 0.00 | 12914817.52 |
Thanks
Lavdeep
Solved! Go to 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 )
)
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
@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
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
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
113 | |
99 | |
85 | |
35 | |
35 |
User | Count |
---|---|
150 | |
100 | |
78 | |
61 | |
56 |