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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Jamey
Helper I
Helper I

Table/Measure Help LASTNONBLANK?

I have a dataset that contains pricing for material, per vendor, and the date range these prices where valid. My goal is to show the price per month and if it changed (price variance). My date slicer is set for all data for this year, however I need to show what that price was at the beinging of the year, so I'm trying to figure out how to see the data prior to the year and then get the LAST price based on the BEG_DATE, per vendor. I came up with a Measure that shows a 1 for dates before the select date range and a 0 what is in the date range. This is the start but I then need to only show the LAST price. Here's a screenshot of what this currently looks like and I'll include the Measure. I will use the 'beginning of year price' as a column in another table. Any help would be greatly appreciated!

Jamey_1-1732226477489.png

Dates B4 Date Range = 
VAR MinDate = CALCULATE( MIN( Dates[Date] ), ALLSELECTED( Dates ) )
VAR MaxDate = MAX( Dates[Date] )
VAR CurrYr = CALCULATETABLE(VALUES(FCI_RAWMAT_PRICE_HIST[PROD_ID]),FILTER(ALLSELECTED(Dates),Dates[Date]>=MinDate && Dates[Date]<=MaxDate))
VAR PrevYr = CALCULATETABLE(VALUES(FCI_RAWMAT_PRICE_HIST[PROD_ID]),FILTER(ALL(Dates),Dates[Date]<MinDate))

VAR Result = EXCEPT(PrevYr,CurrYr)
RETURN
IF(COUNTROWS(Result)>0,COUNTROWS(Result),0)

  

1 ACCEPTED SOLUTION
Poojara_D12
Super User
Super User

Hi @Jamey 

To calculate the beginning-of-year price (last valid price before the selected date range) for each vendor and material, you can use the following DAX measure:

Measure to Get the Last Price Before Date Range:

Beginning of Year Price = 
VAR MinDate = CALCULATE(MIN(Dates[Date]), ALLSELECTED(Dates))
RETURN
CALCULATE(
    MAX(FCI_RAWMAT_PRICE_HIST[PRICE_AMT]),
    FCI_RAWMAT_PRICE_HIST[BEG_DATE] <= MinDate,
    FCI_RAWMAT_PRICE_HIST[END_DATE] >= MinDate,
    REMOVEFILTERS(Dates) -- Ignore any date filters for accurate calculation
)

 

  • Add this measure to your table or matrix.
  • It will display the price valid at the start of the selected date range for each vendor and product.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

View solution in original post

2 REPLIES 2
Poojara_D12
Super User
Super User

Hi @Jamey 

To calculate the beginning-of-year price (last valid price before the selected date range) for each vendor and material, you can use the following DAX measure:

Measure to Get the Last Price Before Date Range:

Beginning of Year Price = 
VAR MinDate = CALCULATE(MIN(Dates[Date]), ALLSELECTED(Dates))
RETURN
CALCULATE(
    MAX(FCI_RAWMAT_PRICE_HIST[PRICE_AMT]),
    FCI_RAWMAT_PRICE_HIST[BEG_DATE] <= MinDate,
    FCI_RAWMAT_PRICE_HIST[END_DATE] >= MinDate,
    REMOVEFILTERS(Dates) -- Ignore any date filters for accurate calculation
)

 

  • Add this measure to your table or matrix.
  • It will display the price valid at the start of the selected date range for each vendor and product.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
FreemanZ
Super User
Super User

hi @Jamey ,

 

could you tell more about "to see the data prior to the year and then get the LAST price based on the BEG_DATE, per vendor"?

ideally describe with examples.

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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