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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SteveDoherty
Regular Visitor

Return highest value in child table and count higher than x number

I have the following data:

Table: Ticket

TicketID
1
2
3
4
5
6
7
8
9
10

 

Table: Time

TimeIDTicketIDValue
1123
2150
3154
4110
5287
6232
7245
825
9310
10320
11443
12437
13451
14595
15538
16573
17561
18667
19652
20762
21767
22813
23850
24964
251017

 

What I need to do is get the highest value from the Time table against the TicketID from the Tickets table.

 

This would give me the following:

TicketIDMax of Value
154
287
320
451
595
667
767
850
964
1017

 

I can achieve that by putting a 1-* relationship between TicketID in Tickets and TicketID in Time, and then adding TicketID from Tickets and Value from Time into a table, and then setting the visual to Max on the Value. However, this just filters the visual and not the underlying data, so when I try to do my next calculation of how many values are higher than 50, it looks at all the values in the Time table instead of just the highest filtered by TicketID.

 

I wrote the following this works, but only in Import mode:

MaxValue = CALCULATE(MAX('Time'[Value]),FILTER('Time','Time'[TicketID]=EARLIER(Tickets[TicketID])))
 
Can anyone help me with what I'm trying to acheive? I need this to work in DirectQuery or have a workaround.
 
To summarise:
Given the data above, I need to obtain the highest number in the value for each TicketID in the Time table and then count how many are higher than 50. This would give me a count of TicketID with the highest value bigger than 50.
 
Thanks in advance
Steve
1 ACCEPTED SOLUTION
SteveDoherty
Regular Visitor

Hi everyone,

 

Thank you so much for your responses on this. It's the first time I've asked a question on this forum and I was humbled with the prompt responses.

 

Unfortuantely the proposed solutions didn't provide the correct output when in DirectQuery mode, so I have gone to the SQL database and created a view directly on there to pull the correct data and then I'm using Power BI to model it.

 

Thanks again

Steve

View solution in original post

7 REPLIES 7
SteveDoherty
Regular Visitor

Hi everyone,

 

Thank you so much for your responses on this. It's the first time I've asked a question on this forum and I was humbled with the prompt responses.

 

Unfortuantely the proposed solutions didn't provide the correct output when in DirectQuery mode, so I have gone to the SQL database and created a view directly on there to pull the correct data and then I'm using Power BI to model it.

 

Thanks again

Steve

amitchandak
Super User
Super User

@SteveDoherty , Create a column in ticket table

MaxValue = MAXX(FILTER('Time','Time'[TicketID]=Tickets[TicketID]),'Time'[Value])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
ryan_mayu
Super User
Super User

@SteveDoherty 

try to create a column.

Column = MAXX(FILTER('time','time'[TicketID]=ticket[TicketID]),'time'[Value])

1.PNG

then create a measure

Measure = CALCULATE(COUNTROWS(ticket),FILTER(ticket,ticket[Column]>50))

 

2.PNG 





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

Proud to be a Super User!




Thank you for your reply.

This isn't working because the Ticket table and Time tables are 1 - many, so the expression cannot find a single row from the Time table.

This works in Import mode, but I cannot use it in DirectQuery mode, as I get this error:

"Function 'MAXX' is not allowed as part of calculated column DAX expressions on DirectQuery models."

Anonymous
Not applicable

Hi @SteveDoherty,

AFAIK, power bi has usage limit on calculating table/columns when you design in direct query mode. (most of DAX functions has been limited to use)
If you want to add a field to your parent table, I'd like to suggest you add tsql statement to your connector to look up child table records and return the highest one as a custom field.

Pull Data from SQL Server with Power BI Designer 

Regards,

Xiaoxin Sheng

Hi,

 

That is what I was thinking I might have to do, but I've not had any experience in T-SQL yet, so it will be a bit of a learning curve. Are there any examples I can find or you could provide to help me with getting started on that?

 

Thanks

 

Greg_Deckler
Super User
Super User

@SteveDoherty - Try this:

MaxValue =

  VAR __TicketID = MAX(Tickets[TicketID])

RETURN

  CALCULATE(MAX('Time'[Value]),FILTER('Time','Time'[TicketID]=__TicketID))

 

Or

 

MaxValue =

  VAR __TicketID = MAX(Tickets[TicketID])

RETURN

  MAXX(FILTER('Time','Time'[TicketID]=__TicketID),'Time'[Value])



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.