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
benh66
Frequent Visitor

Create table of most recent results (with duplicates)

I have a problem that is equivalent to the following. I run a bowling alley, and I want to create a dashboard showing recent scores. I have a table with their names, dates, and scores and I'd like to make a summary showing only the most recent score for each bowler.

 

A possible example of the data is:

Name DateScore
Steve 7/12/2021 300
Richard 6/12/2021 100
Steve 6/12/2021 250
Steve 5/12/2021 270
Bob 5/12/2021 120
Steve 4/12/2021 270
Bob 4/12/2021 130
Richard 4/12/2021 110
Steve 3/12/2021 290
Steve 2/12/2021 280
Bob 2/12/2021 140
Richard 1/12/2021 120

 

My desired output would be:

NameDate of last bowlMost recent score
Bob5/12/2021120
Richard6/12/2021100
Steve7/12/2021300

 

 

Thanks to the help from this community I was able to creating two measures to solve this problem (in most cases):

latestdate = CALCULATE(max('Table'[Date]),ALLEXCEPT('Table','Table'[Name]))
 
latestscore =
var latestdate = CALCULATE(max('Table'[Date]),ALLEXCEPT('Table','Table'[Name]))
Return
CALCULATE(values('Table'[Score]),filter('Table','Table'[Date]=latestdate))
 
However, this does not work in the case where someone went bowling twice on the most recent date.
The error reads: "MdxScript(Model) (8, 11) Calculation error in measure 'Table'[latestscore]: A table of multiple values was supplied where a single value was expected."


Is there any way to force 'latestscore' to only output one value? I've tried a few things but none have worked so far.

 

I've attached the pbix file with and without the error (i.e. with and without duplicate dates)

 

Many thanks for your help! 🙂

 

 

This is a follow on from my earlier question here: Create table of most recent results 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@benh66 here is your measure:

 

Measure 2 = 
VAR __table = CALCULATETABLE ( ALLSELECTED ( Bowling ), VALUES ( Bowling[Name] ) ) 
Var __date =  CALCULATE( MAX(Bowling[ Date] ), __table )
RETURN
CALCULATE ( SUM ( Bowling[Score] ), __table, Bowling[ Date] = __date )

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
benh66
Frequent Visitor
parry2k
Super User
Super User

@benh66  

 

parry2k_0-1640140154418.png

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@benh66 here is your measure:

 

Measure 2 = 
VAR __table = CALCULATETABLE ( ALLSELECTED ( Bowling ), VALUES ( Bowling[Name] ) ) 
Var __date =  CALCULATE( MAX(Bowling[ Date] ), __table )
RETURN
CALCULATE ( SUM ( Bowling[Score] ), __table, Bowling[ Date] = __date )

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks! Worked perfectly 🙂

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.