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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
TarrasQ
Frequent Visitor

Max value for a given quarter, if no quarter value exists, use last known value.

Hi,

I am attempting to work out the best method to return the results of the max value of a column, for a given quarter, while if no results are given, return the last known results. (Since the value should always be increasing, Max value should be sufficient)

 

Something like

= Max(id),allexcept(ID),filter(datemod <= Quarter)

 

Not sure if the best method would be through a measure, or creating a new table with crossjoin (qtr x ID), and populating the fields that way (still unsure of the dax command for that one as well).

 

Link to demo data PBIX

 

DataVersionTable 
IDDate ModifiedValue
Test101-01-201
Test101-02-202
Test201-01-201
Test205-05-202
Test201-10-204
Test301-01-202
Test310-01-203

 

DateTable 
DateQtr
Qtr1
Qtr2
Qtr3
Qtr4

 

Expected Results 
IDQuarterValue
Test1Qtr12
Test1Qtr22
Test1Qtr32
Test1Qtr42
Test2Qtr11
Test2Qtr22
Test2Qtr32
Test2Qtr44
Test3Qtr22
Test3Qtr32
Test3Qtr42
Test3Qtr13

 

Thanks

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @TarrasQ ,

 

First create a column in table as below:

_Quarter = "Q"&QUARTER('Table'[Date])

Then create a table as below:

Table 2 = CROSSJOIN(VALUES(DataVersionTable[ID]),VALUES('Table'[_Quarter]))

Finally create a measure as below:

Measure 2 = 
var _maxselected=CALCULATE(MAX('DataVersionTable'[Value]),FILTER('DataVersionTable','DataVersionTable'[Quater]<=SELECTEDVALUE('Table'[_Quarter])&&'DataVersionTable'[Quater]<=SELECTEDVALUE('Table 2'[_Quarter])&&'DataVersionTable'[ID]=MAX('DataVersionTable'[ID])))
var _maxnotselected=CALCULATE(MAX('DataVersionTable'[Value]),FILTER('DataVersionTable','DataVersionTable'[Quater]<=SELECTEDVALUE('Table 2'[_Quarter])&&'DataVersionTable'[ID]=MAX('DataVersionTable'[ID])))
Return
IF(SELECTEDVALUE('Table'[_Quarter])=BLANK(),
_maxnotselected,_maxselected)

Remember to create a relationship between Table2 and DataversionTable;

Screenshot 2020-10-12 154555.png

And you will see:

Screenshot 2020-10-12 154737.pngScreenshot 2020-10-12 154725.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi @TarrasQ ,

 

First create a column in table as below:

_Quarter = "Q"&QUARTER('Table'[Date])

Then create a table as below:

Table 2 = CROSSJOIN(VALUES(DataVersionTable[ID]),VALUES('Table'[_Quarter]))

Finally create a measure as below:

Measure 2 = 
var _maxselected=CALCULATE(MAX('DataVersionTable'[Value]),FILTER('DataVersionTable','DataVersionTable'[Quater]<=SELECTEDVALUE('Table'[_Quarter])&&'DataVersionTable'[Quater]<=SELECTEDVALUE('Table 2'[_Quarter])&&'DataVersionTable'[ID]=MAX('DataVersionTable'[ID])))
var _maxnotselected=CALCULATE(MAX('DataVersionTable'[Value]),FILTER('DataVersionTable','DataVersionTable'[Quater]<=SELECTEDVALUE('Table 2'[_Quarter])&&'DataVersionTable'[ID]=MAX('DataVersionTable'[ID])))
Return
IF(SELECTEDVALUE('Table'[_Quarter])=BLANK(),
_maxnotselected,_maxselected)

Remember to create a relationship between Table2 and DataversionTable;

Screenshot 2020-10-12 154555.png

And you will see:

Screenshot 2020-10-12 154737.pngScreenshot 2020-10-12 154725.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

Ashish_Mathur
Super User
Super User

Hi,

This article will help you -https://exceleratorbi.com.au/lastnonblank-explained/


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

Found one way to do it, which certainly shouldn't be the correct way.

 

Created an additional table

 

NewTable = CROSSJOIN(VALUES(DataVersionTable[ID]),values('Calendar'[Quater]))
 
Then create a column i can use for date lookup
 
LastdateinQtr = CALCULATE(max('Calendar'[Date]),FILTER('Calendar','Calendar'[Quater] = 'NewTable'[Quarter]))
 
Then to get the value
 
LastMaxValue = CALCULATE(MAX(DataVersionTable[Value]),filter(DataVersionTable,DataVersionTable[Date Modified] <= NewTable[LastdateinQtr]),FILTER(DataVersionTable,DataVersionTable[ID] = 'NewTable'[ID]))
 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors