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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
usernj123
New Member

Max from related table

Hello All,

I have 2 tables as shown below.

Months table: (MonthName is text)

usernj123_0-1708285927640.png

TechSpend:

MonthName      Text

Category   Text

Year          Text

Actuals     Currency

 

TechSpend table has data for all 12 months of 2023 and 1st month of 2024.

Both tables are related using MonthName column. (Months table is on 1 side of Many:1). 

On one of my report, I have a slicer on "Year" and trying to use a Measure to show "Highest MonthName - Total Actuals" in a card.

 

Total Actuals =
VAR ActualExceptOther = ROUND(CALCULATE(sum(TechSpend[Actuals]), TechSpend[Category] <> "Other")/1000,2)
VAR MaxMonth = CALCULATE(FIRSTNONBLANK(TechSpend[Month],1), FILTER(Months, Months[MonthNumber] = max(Months[MonthNumber])))
 
RETURN MaxMonth & " - " & ActualExceptOther & "K".
 
When I run the report with 2024 selected, I get MaxMonth = blank as shown below. Could you please review my code for measure and suggest the changes?
THANKS.
usernj123_1-1708287019333.png

 

 
1 ACCEPTED SOLUTION
nsexton12
Resolver II
Resolver II

I agree with the above comment about creating a proper date table! However, below is a solution anyway. 

----------------------------------------------------------------

VAR FilteredVirtualTable =TOPN(1,FILTER(SUMMARIZE(Months,Months[MonthsName],Months[MonthNum]),Months[MonthsName] IN VALUES(TechSpend[MonthsName])),Months[MonthNum])

VAR MonthNameVirtalTable = SELECTCOLUMNS(FilteredVirtualTable,"Month Name",Months[MonthsName])

RETURN MonthNameVirtalTable 
----------------------------------------------------------------
 
 
You needed to add one more step by creating a virtual table that is all matching rows between your months table and tech spend table, and then take the top row of that table after it is sorted by month number. The last step is using the selected columns function to grab the name of the month from that table. 
 
Please mark as a solution if this worked for you!
 

View solution in original post

4 REPLIES 4
usernj123
New Member

 Thank you all for quick responses!

v-tangjie-msft
Community Support
Community Support

Hi @usernj123 ,

 

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

Total Actuals = 
VAR ActualExceptOther = ROUND(CALCULATE(sum(TechSpend[Actuals]), TechSpend[Category] <> "Other")/1000,2)
VAR _table= ADDCOLUMNS(ALL('TechSpend'),"monthnum",MONTH(CONVERT([MonthName]&" "&1,DATETIME)))
var MaxNum=MAXX(FILTER(_table,[Year] =SELECTEDVALUE('TechSpend'[Year])),[monthnum])
var  MaxMonth=CALCULATE(MAX('Months'[MonthName]),FILTER(ALL('Months'),'Months'[MonthNumber]=MaxNum))
RETURN MaxMonth & " - " & ActualExceptOther & "K"

(3) Then the result is as follows.

vtangjiemsft_0-1708394774810.png

vtangjiemsft_1-1708394783766.png

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. 

nsexton12
Resolver II
Resolver II

I agree with the above comment about creating a proper date table! However, below is a solution anyway. 

----------------------------------------------------------------

VAR FilteredVirtualTable =TOPN(1,FILTER(SUMMARIZE(Months,Months[MonthsName],Months[MonthNum]),Months[MonthsName] IN VALUES(TechSpend[MonthsName])),Months[MonthNum])

VAR MonthNameVirtalTable = SELECTCOLUMNS(FilteredVirtualTable,"Month Name",Months[MonthsName])

RETURN MonthNameVirtalTable 
----------------------------------------------------------------
 
 
You needed to add one more step by creating a virtual table that is all matching rows between your months table and tech spend table, and then take the top row of that table after it is sorted by month number. The last step is using the selected columns function to grab the name of the month from that table. 
 
Please mark as a solution if this worked for you!
 
lbendlin
Super User
Super User

PLease consider using a proper Dates table instead.  It will make your other calculations so much easier.

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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.