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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Syk
Super User
Super User

Count values for a particular day but not if it occurred the day before

Hi! I need some help figuring out how to count each of the values (letters in this case) without counting the values that occurred the day before. Please see the screenshot to explain a little better 🙂

Syk_0-1644603384782.png

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Syk Try:

Measure = 
  VAR __Date = MAX('Table'[Date])
  VAR __DayBefore = __Date - 1
  VAR __Values = DISTINCT('Table'[Value])
  VAR __ValuesDayBefore = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[Date]=__DayBefore),"Value",[Value])
RETURN
  COUNTROWS(EXCEPT(__Values,__ValuesDayBefore))


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:
(my sample data is same as in your example)

Measure 21 =
var cdate = MAX('Table (8)'[Date])
var ldate = calculate(MAX('Table (8)'[Date]),ALL('Table (8)'[Date]),'Table (8)'[Date]<cdate)
var reduce =
COUNTROWS(
INTERSECT(
GROUPBY(
Filter(all('Table (8)'),'Table (8)'[Date]=ldate),'Table (8)'[Value])
, GROUPBY(
Filter(all('Table (8)'),'Table (8)'[Date]=cdate),'Table (8)'[Value])
))
return
COUNT('Table (8)'[Value])-reduce
 
ValtteriN_0-1644606843766.png

 

The idea is to get two tables within a variable (reduce) and then compare them for matching values. The tables are constructed from current date (cdate) and lastdate (ldate). If this interect table's row count is more than 0 it is reduced from the count.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




tamerj1
Super User
Super User

Hi @Syk 

Try this code

Count =
VAR CurrentTable =
SELECTCOLUMNS ( Table, "@Value", Table[Value] )
VAR DayBeforeTable =
CALCULATETABLE ( CurrentTable, Table[Date] = Table[Date] - 1 )
VAR ExceptTable =
EXCEPT ( DayBeforeTable, CurrentTable )
VAR Result =
COUNTROWS ( ExceptTable )
RETURN
Result

DC9A2DFC-A361-4BCB-8B3E-CF0A7B15E2C2.jpeg

Greg_Deckler
Community Champion
Community Champion

@Syk Try:

Measure = 
  VAR __Date = MAX('Table'[Date])
  VAR __DayBefore = __Date - 1
  VAR __Values = DISTINCT('Table'[Value])
  VAR __ValuesDayBefore = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[Date]=__DayBefore),"Value",[Value])
RETURN
  COUNTROWS(EXCEPT(__Values,__ValuesDayBefore))


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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