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

Max of Sum of an Expression

Hi there,

 

A bit of background - I'm trying to work out how many people are in a cafe at any one time based on their entry and exit times (see sample below).  I have managed to do this by creating a new table with crossjoin (Client,Time) 

 

Client

NameCompanyEntry TimeExit Time
JohnA8:009:30
JamesA9:0010:30
VincentB10:0011:30
TomC10:3012:00
SarachB10:3012:00
JaneA9:0010:30
CatherineC9:3011:00
LanaA8:3011:30

 

Time

Time
8:00
8:30
9:00
9:30
10:00

 

Then using IF statements to create an indicator column, to create a table visual:

NameCompanyEntry TimeExit Time8:008:309:009:3010:00
JohnA8:009:301111 
JamesA9:0010:30  111
VincentB10:0011:30    1
TomC10:3012:00     
SarachB10:3012:00     
JaneA9:0010:30  111
CatherineC9:3011:00   11
LanaA8:3011:30 1111

 

What i want to do now is group by Company (which I can) and work out what is the maximum client in the cafe during the day. So I want to work out the "Max" column below.  I'm complete stumped as to how I do this!  Appreciate any insight / help this forum can provide!

 

Company8:008:309:009:3010:00Max
A124434
B000012
C000112
1 REPLY 1
AnthonyTilley
Solution Sage
Solution Sage

do you have a picture of your data model 

 

this shold be easy to accomplish but it depends how your data is formated 

for example if your table is as you have shown above and you have seperate colunms for each time stamp and each of these colunms is added to a matrixs as for example a eash colunm = sum('table'[8:00]) in this instance you can nest a lot of max formulas or if formulas. 

 

for example

Measure = max(max(sum('Table'[8:00]),sum('Table'[8:30])),MAX(sum('Table'[9:00]),sum('Table'[9:30])))

as max only allows 2 values you need to nest many to got to a full days worth 

 

or use an if statment but same problem 

If ([ColumnA] > [ColumnB], if ([ColumnA] > [ColumnC], [ColumnA], [ColumnC]), if ([ColumnB] > [ColumnC], [ColumnB], [ColumnC]))

the alternative is to unpiviot your data

so you have 

 

NameCompanyEntry TimeExit TimeIntervalValue

JohnA08:00:0009:30:008:001
JohnA08:00:0009:30:008:301
JohnA08:00:0009:30:009:001
JohnA08:00:0009:30:009:301
JamesA09:00:0010:30:009:001
JamesA09:00:0010:30:009:301
JamesA09:00:0010:30:0010:001
VincentB10:00:0011:30:0010:001
JaneA09:00:0010:30:009:001
JaneA09:00:0010:30:009:301
JaneA09:00:0010:30:0010:001
CatherineC09:30:0011:00:009:301
CatherineC09:30:0011:00:0010:001
LanaA08:30:0011:30:008:301
LanaA08:30:0011:30:009:001
LanaA08:30:0011:30:009:301
LanaA08:30:0011:30:0010:001

 

the unpivioted data can then be added to a matrixs with interval as the colunm 

and a formula made for the totals inside the matrixs and max for the totals

 

myMax =  maxx(VALUES('table'[Column ID]),CALCULATE(max('table'[Value])))





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

Proud to be a Super User!




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.