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 formula question - getting a count of prior day records

I do not know why this is not working, so maybe someone can help.  I have a table of 32,000+ transaction records and one of the columns is Created, which shows the date and time that the transaction was created.  I have a calculated column to filter out the time and just give me the date.  

 

I now was another calculated column that will show me the prior dates rowcount, if that make sense.  So if I had 20 transactions yesterday, I will get a total of 20, and if that prior day was zero, then I will get a total of zero, and so on.  I have this, but it is not working for some reason: Yesterday = CALCULATE(COUNTROWS(qryGetMEWO),FILTER(qryGetMEWO,qryGetMEWO[ShortDate].[Date]=DATEADD(qryGetMEWO[ShortDate].[Date],-1,DAY)))

 

Maybe I need a measure and not a calculated column?  Ultimately I want to plot each prior day's total on a line chart and do a trendline.

 

Thanks for the information

1 ACCEPTED SOLUTION

I don't know, tough to say. No sample data and no posting of what you are going for. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ 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...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Yeah, if you are doing that in a column, then your filter context isn't going to be correct starting out, you would want to do an ALL and not sure why you are doing a calculate that way, I think what you want would be along the lines of:

 

Yesterday = COUNTROWS(FILTER(ALL(qryGetMEWO),qryGetMEWO[ShortDate].[Date]=DATEADD(qryGetMEWO[ShortDate].[Date],-1,DAY))

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

Should I be using a measure or calculated column?  I would think a measure because a column would put a value in each record, correct?  I also tried your formula: YesterdayWO = COUNTROWS(FILTER(ALL(qryGetMEWO),qryGetMEWO[ShortDate].[Date]=DATEADD(qryGetMEWO[ShortDate].[Date],-1,DAY))) both ways and it is like mine and coming up with no values.  Would it be because the DATEADD is evaluating also with a time and it is not an exact match to the ShortDate column?

I don't know, tough to say. No sample data and no posting of what you are going for. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


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

Actually what I ended up doing is create a separate calculated table using dates and it is correctly doing a count of how many records match the qryMEWO table based on the matching date.  And my line graph is also able to drill down by year, quarter, month, etc.

 

Thanks for the responses

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.