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
Anonymous
Not applicable

DAX: "Sales $ Last Year to Date" is wrong if no date is selected

Hi DAX experts,

 

For "Sales $ Last year to date" measure, my requirement is that if no date is selected/filtered, the period of calculating "Sales $ LYTD" is from beginning of previous year to yesterday's date of previous year. e.g: today is 6th Sep; the perios is from 2016-01-01 to 2016-09-05. My DAX is as followings. I use isfiltered function to check if date is filtered and use different calculation to calculate Sales $ LYTD. It worked fine before. After we removed some data from fact table, full process the tabular cube and the "Sales $ LYTD" become wrong.

 

Sales $ LYTD:=

 

var yesterday= CALCULATE(max('Date'[Date]),filter(all('Date'),'Date'[Day Offset]=0))

 

if(ISFILTERED('Date'[Year]) || ISFILTERED('Date'[Month Desc]) || ISFILTERED('Date'[Day Desc]),
        CALCULATE([Sales $],dateadd(DATESYTD('Date'[Date]),-1,YEAR)),

        CALCULATE(
               [Sales $],
               filter(
                     all('Date'),
                     'Date'[Year]=year(yesterday)-1 && 'Date'[Month Number]<=month(yesterday) && 'Date'[Day Number]<=day(yesterday)
                     )
        )
  )

 

if I filter on date and select a date 2017-09-05, it works perfectly. see below screenshot:

 

expected.PNG

 

If I don't filter on the date, it is wrong. See below screenshot:

currentResult.PNG

 

if I break down the data slicing by region dim, I found subtotal on region level is wrong, the grandtotal just the sum of subtotal, which is wrong either.

incorrectLYTD.PNG

 

if I break down the year, the grand total is wrong:

breakdownyearWrong.PNG

 

note: I have debugged my filter "'Date'[Year]=year(yesterday)-1 && 'Date'[Month Number]<=month(yesterday) && 'Date'[Day Number]<=day(yesterday)", it is as expected. 

 

Can you please advise the root cause and what is further troubleshoting steps I can do? Thank you.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I have found the root cause by myself. My below condition has logic mistake to get correct period. issue resolved now

'Date'[Year]=year(yesterday)-1 && 'Date'[Month Number]<=month(yesterday) && 'Date'[Day Number]<=day(yesterday)

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

I have found the root cause by myself. My below condition has logic mistake to get correct period. issue resolved now

'Date'[Year]=year(yesterday)-1 && 'Date'[Month Number]<=month(yesterday) && 'Date'[Day Number]<=day(yesterday)

could you please share above PBIX file
AB

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.