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

ALLSELECTED Duplicating Table Output

Hi everyone,

 

I've got a problem that I can't seem to find a resolution to that I'm hoping you can help with. What I'm trying to do is calculate the MAX value for all selected rows and display that in a table alongside the actual value for that row. What's happening is that the MAX value is calculated as expected, but rows in the table are being duplicated. I'll start with my data model.

 

DimMarket

IdMarketName
1Market 1
2Market 2

 

FactSales

IdMarketIdSalesIsCurrent
11100True
2250True
3150True
42100True
5160True
6240True
7130False
8220False
9170False
102120False

 

Relationships

image.png

 

Measure

 

MaxSelectedSales = CALCULATE(MAX(FactSales[Sales]), ALLSELECTED(FactSales)) 

 

 

Output

image.png

 

Expected Output

IdMarketNameSalesMaxSelectedSales
1Market 1100100
2Market 250100
3Market 150100
4Market 2100100
5Market 160100
6Market 240100

 

Does anyone know how I can achieve the expected results given the current data model?

 

Thanks in advance!

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi @steveplatz 

You could just adjust it as below:

Step1:

Adjust the formula as below:

New MaxSelectedSales = CALCULATE(MAX(FactSales[Sales]),ALLSELECTED(FactSales),VALUES(DimMarket[MarketName]))
Step2:
change the cross filter direction from "Single" to "Both"

6.JPG

 

Result:

7.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-lili6-msft
Community Support
Community Support

hi @steveplatz 

You could just adjust it as below:

Step1:

Adjust the formula as below:

New MaxSelectedSales = CALCULATE(MAX(FactSales[Sales]),ALLSELECTED(FactSales),VALUES(DimMarket[MarketName]))
Step2:
change the cross filter direction from "Single" to "Both"

6.JPG

 

Result:

7.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

That's close, but the issue is the filter on market name. The original example I provided had a max of 100 for market 1 and market 2, so it makes the output look correct, but if you change the max of market 2 to 140, this is what you end up with.

 

kentyler
Solution Sage
Solution Sage

maxsales.PNGThis what my measure ended up like

Max Sales per Market =
VAR cur_Market =
    SELECTEDVALUE ( Sales[MarketId] )
VAR total_sales_per_market =
    CALCULATE ( MAX ( Sales[Sales] )ALL ( Sales ), Sales[MarketId] = cur_Market )
RETURN
    total_sales_per_market

in a problem like this the first step is to get the value you want to filter by out of the current filter context-- in this case SELECTEDVALUE() does that-- and store it in a variable

the next step is to do your calculation-- inside the CALCULATE() I use ALL() to remove any filters on the Sales table coming from the external filter context (like the one from the table visual that gets the values for a specific row) and use the saved variable as a filter to get only the rows I want the MAX of

 

 

Power BI is easy to learn, but it has hard parts.
I'm a personal Power Bi Trainer I learn something every time I answer a question

 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


@kentyler Thanks for the detailed response. That makes sense and works if I'm looking for the max per market, but what I'm trying to accomplish is to get the MAX value of all selected records, taking any outside filters into account. This is a simplified example with only the IsCurrent and Market filters, but there could be much more.

 

Do you know how I would accomplish that?

You can change to ALLSELECTED

Max Sales per Market = VAR cur_Market = SELECTEDVALUE(Sales[MarketId])
VAR total_sales_per_market = CALCULATE(max(Sales[Sales]),ALLSELECTED(Sales),Sales[MarketId]=cur_Market) return total_sales_per_market
That seems to take both a store slicer and an iscurrent slicer into account
true.PNG
false.PNG
 




Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


This works when filtered to a specific market, but not when all markets are displayed. I changed the MAX for "Market 2" to be different than Market 1 and get this result:

 

image.png

 

What I'd like to see is 140 for every cell in MaxSelectedSales2.

 

Maybe you need to remove the filter on just one market in line 3.

 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


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.