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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
DavidNunes7
Helper I
Helper I

Measure for earlier and later dates

Hello everybody

I'm having trouble creating a measure to meet the following requirements:

I have a table where there are the inspection records of places with the date and note I need to create a table visual where my measure will return me:

  • For previous months that have no record, return the same value as the oldest recorded date;
  • For subsequent months that have no records, return the same value as the most recently recorded date                                                            
  • print.png
1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @DavidNunes7 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table and a measure. 

CALENDAR = ADDCOLUMNS(CALENDAR(DATE(2023,1,1),DATE(2023,12,31)),
"Month",FORMAT([Date],"MMMM"))
Measure 2 = var a=MAXX(FILTER(ALLSELECTED('Table'),[site name] in VALUES('Table'[site name])&&[Result]<>BLANK()),[Date])
var b=CALCULATE(SUM('Table'[Result]),FILTER('Table',EOMONTH('Table'[Date],0)=EOMONTH(MAX('CALENDAR'[Date]),0)))
var c=MINX(FILTER(ALLSELECTED('Table'),[site name] in VALUES('Table'[site name])&&[Result]<>BLANK()),[Date])
return IF(b<>BLANK(),b,IF(b=BLANK()&&MAX('CALENDAR'[Date])>a,CALCULATE(SUM('Table'[Result]),'Table'[Date]=a),IF(b=BLANK()&&MAX('CALENDAR'[Date])<C,CALCULATE(SUM('Table'[Result]),'Table'[Date]=C))))

(3) Then the result is as follows.

vtangjiemsft_0-1694166394679.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Please find attached the PBI file.

Hope this helps.

Ashish_Mathur_0-1694305379960.png

 


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

Could you give me the measurement formula?
I can't open the file because your BI version is newer,

That will be way too many steps to list.  Please retry/try on another machine with an updated version.


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

Perfect!!!!
Thank You 🙂

v-tangjie-msft
Community Support
Community Support

Hi @DavidNunes7 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table and a measure. 

CALENDAR = ADDCOLUMNS(CALENDAR(DATE(2023,1,1),DATE(2023,12,31)),
"Month",FORMAT([Date],"MMMM"))
Measure 2 = var a=MAXX(FILTER(ALLSELECTED('Table'),[site name] in VALUES('Table'[site name])&&[Result]<>BLANK()),[Date])
var b=CALCULATE(SUM('Table'[Result]),FILTER('Table',EOMONTH('Table'[Date],0)=EOMONTH(MAX('CALENDAR'[Date]),0)))
var c=MINX(FILTER(ALLSELECTED('Table'),[site name] in VALUES('Table'[site name])&&[Result]<>BLANK()),[Date])
return IF(b<>BLANK(),b,IF(b=BLANK()&&MAX('CALENDAR'[Date])>a,CALCULATE(SUM('Table'[Result]),'Table'[Date]=a),IF(b=BLANK()&&MAX('CALENDAR'[Date])<C,CALCULATE(SUM('Table'[Result]),'Table'[Date]=C))))

(3) Then the result is as follows.

vtangjiemsft_0-1694166394679.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors