PQ - True/False expression used in a filter table expression

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there,

I have the below DAX function that needs to calculate SUM of the Values from Last Year to Date, however I am apparently using LASTDATE Incorrectly in the DAX Function.

The Below code is the one with the Error.
Code:
LYTD Rands = CALCULATE(SUM(MASTER_SALES[VALUE]),MASTER_SALES[YEAR]=YEAR(TODAY())-1,MASTER_SALES[MONTH]<=MONTH(LASTDATE(MASTER_SALES[DATE])))

This code works however it is not what I want as the Today is not correct in the way out data is collected.
Code:
LYTD Rands = CALCULATE(SUM(MASTER_SALES[VALUE]),MASTER_SALES[YEAR]=YEAR(TODAY())-1,MASTER_SALES[MONTH]<=MONTH(TODAY()))

I need to adjust the first DAC Function to take the month of the latest Date.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
ok, after a bit more digging I found the following which works


This is the one for Last Year To Date
Code:
LYTD Rands = CALCULATE([Total Rands],DATEADD(DATESYTD(MASTER_SALES[DATE]),-1,YEAR))

Now this now is for This Year To Date
Code:
TYTD Rands = CALCULATE([Total Rands],DATESYTD(MASTER_SALES[DATE]))

The interesting thing is that when I filter (Using a slicer on PBI Desktop) on a year i.e. 2015 the LYTD result goes to blank as expected, however the TYTD gets a very strange result. Can someone explain why? (Just curious ).
 
Upvote 0
I would definitely recommend having a separate Calendar table with all dates inclusive of the range you are working on. Date functions in Dax work by shifting the dates in the filter context, not by creating a Date list or perform other math on Dates. Nor will the Date functions remove filters on other columns the way you have used it which will impact the Dates returned. Hard to say without seeing your model exactly what is happening. So having a separate Calendar table i think will prove much easier to use. Then you can use the built in time intelligence functions which are easier to use and read.
Code:
TYTD Rands = TOTALYTD ( [Total Rands], Calendar[Date] )
Code:
LYTD Rands = TOTALYTD ( [Total Rands], SAMEPERIODLASTYEAR( Calendar[Date] ) )
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,985
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top