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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Tn_Gartn
Frequent Visitor

Last year(previous year) YTD/QTD/MTD DAX formula when time table has data at weekly grain

Hi All,

 

I am trying to calculate Last Year YTD,QTD& MTD. My data in the table is at the weekly grain.  i used following formula but this is giving me blank value.

Last year TOTALYTD =TOTALYTD(SUM(Sales[Sales]),SAMEPERIODLASTYEAR(DATESYTD('Time'[week])))

Last year TOTALQTD =TOTALQTD(SUM(Sales[Sales]),SAMEPERIODLASTYEAR(DATESQTD('Time'[week])))

Last year TOTALMTD =TOTALMTD(SUM(Sales[Sales]),SAMEPERIODLASTYEAR(DATESMTD('Time'[week])))

 

in this data set I am selecting week 10/20/2018 as a filter and expecting the sales number should be as below.

TOTAL YTD2983Totallast year YTD1281TOTAL QTD288TotalPYQTD150

 

So for 10/20/2018 week last year week would be 10/21/2017 which is different than the simple time dimension.

Note: I am able to correctly calculate YTD,QTD,MTD  using 

TOTALYTD = TOTALYTD(SUM(Sales[Sales]),'Time'[week])

TOTALQTD = TOTALQTD(SUM(Sales[Sales]),'Time'[week])

TOTALMTD = TOTALMTD(SUM(Sales[Sales]),'Time'[week])

 

Appreciate your help in finding the right solution for this in advance!

 

Time table:

 

ROWWIDWeekPY Week
1001201701070001/7/20171/2/2016
1001201701140001/14/20171/9/2016
1001201701210001/21/20171/16/2016
1001201701280001/28/20171/23/2016
1001201702040002/4/20171/30/2016
1001201702110002/11/20172/6/2016
1001201702180002/18/20172/13/2016
1001201702250002/25/20172/20/2016
1001201703040003/4/20172/27/2016
1001201703110003/11/20173/5/2016
1001201703180003/18/20173/12/2016
1001201703250003/25/20173/19/2016
1001201704010004/1/20173/26/2016
1001201704080004/8/20174/2/2016
1001201704150004/15/20174/9/2016
1001201704220004/22/20174/16/2016
1001201704290004/29/20174/23/2016
1001201705060005/6/20174/30/2016
1001201705130005/13/20175/7/2016
1001201705200005/20/20175/14/2016
1001201705270005/27/20175/21/2016
1001201706030006/3/20175/28/2016
1001201706100006/10/20176/4/2016
1001201706170006/17/20176/11/2016
1001201706240006/24/20176/18/2016
1001201707010007/1/20176/25/2016
1001201707080007/8/20177/2/2016
1001201707150007/15/20177/9/2016
1001201707220007/22/20177/16/2016
1001201707290007/29/20177/23/2016
1001201708050008/5/20177/30/2016
1001201708120008/12/20178/6/2016
1001201708190008/19/20178/13/2016
1001201708260008/26/20178/20/2016
1001201709020009/2/20178/27/2016
1001201709090009/9/20179/3/2016
1001201709160009/16/20179/10/2016
1001201709230009/23/20179/17/2016
1001201709300009/30/20179/24/2016
10012017100700010/7/201710/1/2016
10012017101400010/14/201710/8/2016
10012017102100010/21/201710/15/2016
10012017102800010/28/201710/22/2016
10012017110400011/4/201710/29/2016
10012017111100011/11/201711/5/2016
10012017111800011/18/201711/12/2016
10012017112500011/25/201711/19/2016
10012017120200012/2/201711/26/2016
10012017120900012/9/201712/3/2016
10012017121600012/16/201712/10/2016
1001201801060001/6/20181/7/2017
1001201801130001/13/20181/14/2017
1001201801200001/20/20181/21/2017
1001201801270001/27/20181/28/2017
1001201802030002/3/20182/4/2017
1001201802100002/10/20182/11/2017
1001201802170002/17/20182/18/2017
1001201802240002/24/20182/25/2017
1001201803100003/10/20183/11/2017
1001201804070004/7/20184/8/2017
1001201804140004/14/20184/15/2017
1001201804210004/21/20184/22/2017
1001201804280004/28/20184/29/2017
1001201805050005/5/20185/6/2017
1001201805120005/12/20185/13/2017
1001201805190005/19/20185/20/2017
1001201805260005/26/20185/27/2017
1001201806020006/2/20186/3/2017
1001201806090006/9/20186/10/2017
1001201806160006/16/20186/17/2017
1001201806230006/23/20186/24/2017
1001201806300006/30/20187/1/2017
1001201807070007/7/20187/8/2017
1001201807140007/14/20187/15/2017
1001201807210007/21/20187/22/2017
1001201807280007/28/20187/29/2017
1001201808040008/4/20188/5/2017
1001201808110008/11/20188/12/2017
1001201808180008/18/20188/19/2017
1001201808250008/25/20188/26/2017
1001201809010009/1/20189/2/2017
1001201809080009/8/20189/9/2017
1001201809150009/15/20189/16/2017
1001201809220009/22/20189/23/2017
1001201809290009/29/20189/30/2017
10012018100600010/6/201810/7/2017
10012018101300010/13/201810/14/2017
10012018102000010/20/2018

10/21/2017

 

 

Sales table

TIMEROWWIDSales Number
10012017010700010
10012017011400011
10012017012100012
10012017012800013
10012017020400014
10012017021100015
10012017021800016
10012017022500017
10012017030400018
10012017031100019
10012017031800020
10012017032500021
10012017040100022
10012017040800023
10012017041500024
10012017042200025
10012017042900026
10012017050600027
10012017051300028
10012017052000029
10012017052700030
10012017060300031
10012017061000032
10012017061700033
10012017062400034
10012017070100035
10012017070800036
10012017071500037
10012017072200038
10012017072900039
10012017080500040
10012017081200041
10012017081900042
10012017082600043
10012017090200044
10012017090900045
10012017091600046
10012017092300047
10012017093000048
10012017100700049
10012017101400050
10012017102100051
10012017102800052
10012017110400053
10012017111100054
10012017111800055
10012017112500056
10012017120200057
10012017120900058
10012017121600059
10012018010600060
10012018011300061
10012018012000062
10012018012700063
10012018020300064
10012018021000065
10012018021700066
10012018022400067
10012018031000068
10012018040700069
10012018041400070
10012018042100071
10012018042800072
10012018050500073
10012018051200074
10012018051900075
10012018052600076
10012018060200077
10012018060900078
10012018061600079
10012018062300080
10012018063000081
10012018070700082
10012018071400083
10012018072100084
10012018072800085
10012018080400086
10012018081100087
10012018081800088
10012018082500089
10012018090100090
10012018090800091
10012018091500092
10012018092200093
10012018092900094
10012018100600095
10012018101300096
10012018102000097

 

1 ACCEPTED SOLUTION

Sam Thanks for the reply. I will try and let you know if it works. Meanwhile, I used following DAX For last year QTD and it calculates sales correctly.

 

Last YearQTD =

CALCULATE (
SUM ('Sale'[Sale]),
FILTER (
ALL ( 'Time'[Week]),
'Time'[Week] <= max('Time'[PY Week])
&& ROUNDUP( MONTH('Time'[Week])/3,0)=ROUNDUP( MONTH(max('Time'[PY Week]))/3,0) && YEAR ( 'Time'[week] ) = YEAR (max('Time'[PY Week]))))

 

 

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Tn_Gartn,

 

You may try the measure below.

Measure =
VAR t =
    DATESQTD ( 'Time'[PY Week] )
RETURN
    CALCULATE ( SUM ( Sales[Sales] ), CONTAINSROW ( t, 'Time'[Week] ) )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sam Thanks for the reply. I will try and let you know if it works. Meanwhile, I used following DAX For last year QTD and it calculates sales correctly.

 

Last YearQTD =

CALCULATE (
SUM ('Sale'[Sale]),
FILTER (
ALL ( 'Time'[Week]),
'Time'[Week] <= max('Time'[PY Week])
&& ROUNDUP( MONTH('Time'[Week])/3,0)=ROUNDUP( MONTH(max('Time'[PY Week]))/3,0) && YEAR ( 'Time'[week] ) = YEAR (max('Time'[PY Week]))))

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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