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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
jam17
Helper I
Helper I

Gauge min and max values help

I am working with a few different tables and am trying to show various pieces of information on a single dashboard: a mix of specific details about a customer, and some aggregate information about that customer's larger account (1 among many accounts).

Here is what I have so far, and what I am trying to accomplish:
Sales Table

customer_idYearsale amount
12023$45
12024$45
12024$5
22024$20
32024$75
42024-$10


Customer Table

customer_idcustomer_name
1John Doe
2Kathy Sims
3Bret Heart
4Pat Blaine

 

Account Table

account_idaccount_name
100Curious Cat
200Dainty Dog
300Fancy Ferrets

 

Customer Account Join Table

customer_idaccount_id
1100
2100
3200
4300


I have a slicer on my dashboard, along with a filter set to 2024, such that you could select John Doe and it will bring up a table of just his transactions from 2024, which will have a total row so you can see his total sales ($50).

With the following measure, I can also have a card populate the total transactions for his account (100) in 2024: $70
Account Total Sales = CALULATE(SUM(`SALES TABLE`[Sale Amount]),ALL(`Customer Account Join Table`,VALUES(`Customer Account Join Table`[account_id))

What I am trying to accomplish now is using a gauge to display how John Doe's account compare to the other accounts, but I can't figure out how to set properly set the Max and Mins.  In other words, when clicking on John Doe, the gauge will display Total Sales for his account $70 - with the gauge min being the lowest amount (-$10, Fancy Ferrets has only had a refund this year) and the highest amount ($75 for Dainty Dogs). In contrast, if I clicked on Kathy Sims, it would update the table to her transactions, but the guage would remain the same (since she belongs to the same account as John Doe), but would shift if a customer from a different account was chosen (keeping the min and max the same).

This way rather than using three different cards (one for Curious Cat - the account of the selected customer; one for the max; and one for the min), I can put all three pieces of this information in one visualization that will also display how close to the value is to the max/min (i.e. how much Curious Cat stacks up relative to other accounts, not some hard coded min/max).

The biggest problem I'm finding is because Account Total Sales is a measure, I can't put further aggregates on it, like min/max. 
What are my options?

1 ACCEPTED SOLUTION
jam17
Helper I
Helper I

Here is what ended up working for me: 
AccountTotalSales = 

CACLULATE(

SUM(`Sales Table`[sale amount]),

ALL(`Customer Account Join Table'),

VALUES(`Customer Account Join Table[account_id])

)

 

MaxAccountSales = 

MAXX(

SUMMARIZE(

ALL(`Customer Account Join Table`),

'Customer Account Join Table'[account_id],

"Max Sales",

CACLULATE(

SUM(`Sales Table`[sale amount]),

ALL(`Customer Account Join Table'),

VALUES(`Customer Account Join Table[account_id])

),

[Max Sales]

)

 

MinAccountSales = 

MINX(

SUMMARIZE(

ALL(`Customer Account Join Table`),

'Customer Account Join Table'[account_id],

"Min Sales",

CACLULATE(

SUM(`Sales Table`[sale amount]),

ALL(`Customer Account Join Table'),

VALUES(`Customer Account Join Table[account_id])

),

[Min Sales]

)

 

All of these are responsive to any filters I add to the page, so I don't need to make my code reference them.

 

View solution in original post

5 REPLIES 5
jam17
Helper I
Helper I

Here is what ended up working for me: 
AccountTotalSales = 

CACLULATE(

SUM(`Sales Table`[sale amount]),

ALL(`Customer Account Join Table'),

VALUES(`Customer Account Join Table[account_id])

)

 

MaxAccountSales = 

MAXX(

SUMMARIZE(

ALL(`Customer Account Join Table`),

'Customer Account Join Table'[account_id],

"Max Sales",

CACLULATE(

SUM(`Sales Table`[sale amount]),

ALL(`Customer Account Join Table'),

VALUES(`Customer Account Join Table[account_id])

),

[Max Sales]

)

 

MinAccountSales = 

MINX(

SUMMARIZE(

ALL(`Customer Account Join Table`),

'Customer Account Join Table'[account_id],

"Min Sales",

CACLULATE(

SUM(`Sales Table`[sale amount]),

ALL(`Customer Account Join Table'),

VALUES(`Customer Account Join Table[account_id])

),

[Min Sales]

)

 

All of these are responsive to any filters I add to the page, so I don't need to make my code reference them.

 

Anonymous
Not applicable

Thanks for the reply from Sahir_Maharaj , please allow me to provide another insight: 
Hi  @jam17 ,

 

Here are the steps you can follow:

1. Create measure.

compare =
var _selectyear=SELECTEDVALUE('Sales Table'[Year])
var _selectcustomername=SELECTEDVALUE('Customer Table'[customer_name])
var _customerid=MAXX(FILTER(ALL('Customer Table'),'Customer Table'[customer_name]=_selectcustomername),[customer_id])
var _accountid=MAXX(FILTER(ALL('Customer Account Join Table'),'Customer Account Join Table'[customer_id]=_customerid),[account_id])
var _cusomeridcolumn=SELECTCOLUMNS(FILTER(ALL('Customer Account Join Table'),'Customer Account Join Table'[account_id]=_accountid),"test",'Customer Account Join Table'[customer_id])
return
SUMX(
    FILTER(ALL('Sales Table'),'Sales Table'[Year]=_selectyear&&'Sales Table'[customer_id] IN _cusomeridcolumn),[sale amount])
Min =
var _selectyear=SELECTEDVALUE('Sales Table'[Year])
var _table1=
ADDCOLUMNS(
    'Account Table',"Test",CONCATENATEX(FILTER(ALL('Customer Account Join Table'),[account_id]=EARLIER('Account Table'[account_id])),'Customer Account Join Table'[customer_id],"-"))
var _table2=
ADDCOLUMNS(
    _table1,"Value",SUMX(FILTER(ALL('Sales Table'),'Sales Table'[Year]=_selectyear&&CONTAINSSTRING([Test],'Sales Table'[customer_id])=TRUE()),[sale amount]))
return
MINX(_table2,[Value])
Max =
var _selectyear=SELECTEDVALUE('Sales Table'[Year])
var _table1=
ADDCOLUMNS(
    'Account Table',"Test",CONCATENATEX(FILTER(ALL('Customer Account Join Table'),[account_id]=EARLIER('Account Table'[account_id])),'Customer Account Join Table'[customer_id],"-"))
var _table2=
ADDCOLUMNS(
    _table1,"Value",SUMX(FILTER(ALL('Sales Table'),'Sales Table'[Year]=_selectyear&&CONTAINSSTRING([Test],'Sales Table'[customer_id])=TRUE()),[sale amount]))
return
MAXX(_table2,[Value])

2. Result:

vyangliumsft_0-1726131360908.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Sahir_Maharaj
Super User
Super User

Hello @jam17,

 

Can you please try this approach:

 

1. Create a Measure for Total Sales per Account

AccountTotalSales = 
CALCULATE(
    SUM('Sales Table'[sale amount]),
    ALL('Customer Account Join Table', 'Customer Table', 'Account Table'),
    'Customer Account Join Table'[account_id] = 
        SELECTEDVALUE('Customer Account Join Table'[account_id])
)

2. Create a Measure for the Minimum Sales across All Accounts

MinAccountSales = 
MINX(
    SUMMARIZE(
        ALL('Account Table'),
        'Account Table'[account_id],
        "TotalSales", 
        CALCULATE(
            SUM('Sales Table'[sale amount]),
            'Customer Account Join Table'[account_id] = 'Account Table'[account_id],
            'Sales Table'[Year] = 2024
        )
    ),
    [TotalSales]
)

3. Create a Measure for the Maximum Sales across All Accounts

MaxAccountSales = 
MAXX(
    SUMMARIZE(
        ALL('Account Table'),
        'Account Table'[account_id],
        "TotalSales", 
        CALCULATE(
            SUM('Sales Table'[sale amount]),
            'Customer Account Join Table'[account_id] = 'Account Table'[account_id],
            'Sales Table'[Year] = 2024
        )
    ),
    [TotalSales]
)

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

I am also getting an error with the following line:

'Customer Account Join Table'[account_id] = 'Account Table'[account_id],

It says "The expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression".

By setting 

'Sales Table'[Year] = 2024

is that hard coding it?

How could I make the min/max be dynamic to the year selected by the filter?
Likewise, what if I wanted to add another filter, such as region?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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