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
dkel6177
Regular Visitor

DAX: YTD and PYTD questions

I have a dashboard with a table view that has categories of crime along the left side and columns of totals for YTD figures and Previous YTD figures. On the current year or monthly totals the figures are correct. If it is the first few days in January I get correct numbers for the current month, but on all previous time calculations I get the totals for the entire month and the formulas do not respect the partial days in the current month. For instance,.... if I run the report for the first 5 days in January I would like the previous calculations for the year prior to respect only those first 5 days in January as well. Also I cannot share the model for obvious reasons. Any help would be appreciated. 

 

My YTD DAX:

YTD = CALCULATE(DISTINCTCOUNT(lwmain[lwmainid]),DATESYTD(MasterDate[Date])) 

 

My PYTD DAX:

LYTD = CALCULATE(DISTINCTCOUNT(lwmain[lwmainid]), DATEADD(DATESYTD(MasterDate[Date]),-1,YEAR)) 

 

My MTD DAX:

MTD = CALCULATE(DISTINCTCOUNT(lwmain[lwmainid]),DATESMTD(MasterDate[Date]))

 

My PMTD DAX:

LYMTD = CALCULATE(DISTINCTCOUNT(lwmain[lwmainid]),DATEADD(DATESMTD(MasterDate[Date]), -1,YEAR))

 

Table.png

 

1 ACCEPTED SOLUTION
Ssingh
Frequent Visitor

Use of DATESBETWEEN and EDATE functions should resolve this, please check this.

LYMTD = CALCULATE(DISTINCTCOUNT(lwmain[lwmainid]),DATESBETWEEN(MasterDate[Date], EDATE(STARTOFMONTH(MasterDate[Date]),-12),
EDATE(TODAY(),-12)
))

View solution in original post

4 REPLIES 4
AlecMaly
New Member

How did you get the status icons for KP_ and K_ columns?

CheenuSing
Community Champion
Community Champion

Hi @dkel6177

 

Please check out the link

 

 

http://community.powerbi.com/t5/Desktop/How-to-display-sales-YTD-and-sales-last-YTD-over-years/m-p/1...

 

 

If this solves your issue please give KUDOS.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
Ssingh
Frequent Visitor

Use of DATESBETWEEN and EDATE functions should resolve this, please check this.

LYMTD = CALCULATE(DISTINCTCOUNT(lwmain[lwmainid]),DATESBETWEEN(MasterDate[Date], EDATE(STARTOFMONTH(MasterDate[Date]),-12),
EDATE(TODAY(),-12)
))

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.

Top Solution Authors