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
SaChinKuMarT
Frequent Visitor

DAX formula to find the previous day count

Hi I need a solution to find the previous days count. Where if i click today's date it should show the Yesterday's result.

 

SaChinKuMarT_1-1680457169206.png

 

As an sample i have attached a screenshot here. 

 

Kindly help with your ideas thank you.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1680466493163.png

Selected day count measure: = 
COUNTROWS( Data )

 

Previous day count measure: = 
CALCULATE ( [Selected day count measure:], Data[Date] = MAX ( Data[Date] ) - 1 )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1680466493163.png

Selected day count measure: = 
COUNTROWS( Data )

 

Previous day count measure: = 
CALCULATE ( [Selected day count measure:], Data[Date] = MAX ( Data[Date] ) - 1 )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thank you so much JIHWAN_Kim

hah, your solution looks simpler and faster than mine Jihwan. 😄

 

My only comment is I do still prefer SELECTEDVALUE to MAX because the measure only makes sense if exactly one date is selected.

Wilson_
Memorable Member
Memorable Member

Hello!

 

Try the below measure out and let me know whether it works for you or not. 😄

 

Yesterday Count = 
VAR Yesterday = SELECTEDVALUE ( Table1[Date] ) - 1

-- Filters your data for yesterday's row
VAR FilteredTable =
FILTER (
    ALL ( Table1 ),
    Table1[Date] = Yesterday
)

RETURN
SUMX (
    FilteredTable,
    Table1[Count]
)

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.