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
dpombal
Post Patron
Post Patron

EARLIER with a new measure instead new column

I have this initial data set

 

initial data.PNG

I require the count of  products  for the previous Existing date.

New measure

Product Count = COUNT('Table'[ProductID])

New Column

PreviousDayValue =
var PreviousDate = CALCULATE( MAX('Table'[Date]); FILTER('Table';  'Table'[Date] < EARLIER('Table'[Date])))
return CALCULATE( [Product Count]; FILTER('Table'; 'Table'[Date] = PreviousDate) )

 

 My problem is that Calculated columns doesn't filter if i add slicers to  my report. Below I add an example with an slicer for product type.

 

with without slicers.PNG

 

 

PrevDay Value only works if I do not use any slicer, how to convert this in a new measure?

 

powerBI_new_column.PNG

 

1 ACCEPTED SOLUTION

Hi @dpombal,

 

You can modify the measure like below: 

 

Measure = var PreDate=MAXX(FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])),'Table'[Date])
var tmp=CALCULATE(COUNT('Table'[ProductID]),FILTER(ALLSELECTED('Table'),'Table'[Date]=PreDate))
var selected=ALLSELECTED('Table'[ProductType])
return
IF(tmp<>BLANK(),tmp,CALCULATE(COUNT('Table'[ProductID]),FILTER(ALL('Table'),'Table'[Date]=PreDate && 'Table'[ProductType] in selected)) )

 

w2.PNGw2.PNG

 

 

By the way, as your previous issue is solved based on my previous post. If you have more requirements, please create a new thread and share detail information. 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-qiuyu-msft
Community Support
Community Support

Hi @dpombal,

 

You can create a measure below: 

 

Measure = var PreDate=MAXX(FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])),'Table'[Date])
return CALCULATE(COUNT('Table'[ProductID]),FILTER(ALLSELECTED('Table'),'Table'[Date]=PreDate)) 

 

q4.PNGq5.PNG

 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-qiuyu-msft  your solution is close to work for me , just a little issue

 

 

If i add a period slicer with (like below) day 1 of each month is not calculated since it requires data from last day of previous month

 

Here it is the PBIX https://1drv.ms/u/s!Am7buNMZi-gwi298rItJUbxzPuSU

 

Table with period column.PNG

PowerBI Report PBIX.PNG

 

Hi @dpombal,

 

You can modify the measure like below: 

 

Measure = var PreDate=MAXX(FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])),'Table'[Date])
var tmp=CALCULATE(COUNT('Table'[ProductID]),FILTER(ALLSELECTED('Table'),'Table'[Date]=PreDate))
var selected=ALLSELECTED('Table'[ProductType])
return
IF(tmp<>BLANK(),tmp,CALCULATE(COUNT('Table'[ProductID]),FILTER(ALL('Table'),'Table'[Date]=PreDate && 'Table'[ProductType] in selected)) )

 

w2.PNGw2.PNG

 

 

By the way, as your previous issue is solved based on my previous post. If you have more requirements, please create a new thread and share detail information. 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-qiuyu-msft just one final question, If i require more slicers like product type. Is it correct adding it on ALLSELECTED? or which is an aproximate syntax

 

 

Measure = var PreDate=MAXX(FILTER(ALL('Table');'Table'[Date]<MAX('Table'[Date]));'Table'[Date])
var tmp=CALCULATE(COUNT('Table'[ProductID]);FILTER(ALLSELECTED('Table');'Table'[Date]=PreDate))
var selected=ALLSELECTED('Table'[ProductType], 'Table'[Othercol))  
return
IF(tmp<>BLANK();tmp;CALCULATE(COUNT('Table'[ProductID]);FILTER(ALL('Table');'Table'[Date]=PreDate && 'Table'[ProductType] in selected)) )

 

 

. I don't understand correctly. what you tell me for creating new threads.

dpombal
Post Patron
Post Patron

Here there is a link to PBIX report

 

 

https://1drv.ms/u/s!Am7buNMZi-gwi2wTE_usJwezZMNE

Hi,

 

I first created a calendar table using this formula and then created a relationship.  I dragged the date from the calendar table into the visual

 

=CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

I then created the following calculated field formula to compute the previous day producr count

 

=if(OR(ISBLANK([Product Count]),ISBLANK(CALCULATE(MAX('Table'[Date]),DATESBETWEEN('Calendar'[Date],DATE(2017,1,1),MAX('Calendar'[Date])-1)))),BLANK(),CALCULATE([Product Count],DATESBETWEEN('Calendar'[Date],CALCULATE(MAX('Table'[Date]),DATESBETWEEN('Calendar'[Date],DATE(2017,1,1),MAX('Calendar'[Date])-1)),CALCULATE(MAX('Table'[Date]),DATESBETWEEN('Calendar'[Date],DATE(2017,1,1),MAX('Calendar'[Date])-1)))))

Untitled.pngUntitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.