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
joerykeizer
Helper II
Helper II

DAX: Views since last transaction

Hi all,

 

I have a table which contains: Date, ProductID, Views, Transactions. 

Now I would like to see the number of views since the last transaction for each product. To calculate the last transaction date I use the following measure: [LastTransaction] = calculate(max(date);conversions>0;all(date))

 

For the views since last transaction I tried = calculate(sum(views);date>[LastTransaction]) but it gives me an error ("A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression."). I also tried using the Filter() command but I seemed to ignore the Date>LastTransaction statement.

 

I could use some help!

1 ACCEPTED SOLUTION

@joerykeizer

 

In this scenario, you can use FILTER() to filter dates later that you calcuated Last Transaction Date. The expression can be like:

 

ClicksSinceLastTransaction = CALCULATE(SUM(Sheet1[Views]),FILTER(ALL(Sheet1[Date]),Sheet1[Date]>Sheet1[LastTransaction]))

666.PNG

 

 

I also attached modifed .pbix file

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Right, so if you expand out your formual, you essentially have:

 

calculate(sum(views);date>calculate(max(date);conversions>0;all(date))

So, you are essentially using CALCULATE in a Filter condition which is not allowed.

 

You might try using MAXX instead of CALCULATE and see if that resolves the issue. And perhaps SUMX instead of CALCULATE. I'd have to play with it. Any chance you can post sample data?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Not sure if there is an easier way to post this but I've created & uploaded a small sample file for you to look at.

 

 

@joerykeizer

 

In this scenario, you can use FILTER() to filter dates later that you calcuated Last Transaction Date. The expression can be like:

 

ClicksSinceLastTransaction = CALCULATE(SUM(Sheet1[Views]),FILTER(ALL(Sheet1[Date]),Sheet1[Date]>Sheet1[LastTransaction]))

666.PNG

 

 

I also attached modifed .pbix file

Thank you very much, I tried the filter but messed up the All(Date) part, I get it now.

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.