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

Show only lowest average per category with filters

Hi friends!

 

We have a list of quotes of services, where a client can receive in the same quote a list of services available with a variable price, and not available services are returned with a price of zero. There are other information on each quote, such as the Quote Date (Format dd/mm/yyyy) and the State from where the client has made the quote, here is a sample of a quote:

 

QuoteNumberQuoteDateServiceService CategoryPriceState
31005617/02/2021Service CCompleteR$ 0BA
31005617/02/2021Service C-1BasicR$ 0BA
31005617/02/2021Service HCompleteR$ 0BA
31005617/02/2021Service H-1SimpleR$ 3.984BA
31005617/02/2021Service H-2PopularR$ 5.823BA
31005617/02/2021Service LCompleteR$ 0BA
31005617/02/2021Service L-1PopularR$ 0BA
31005617/02/2021Service L-2BasicR$ 0BA
31005617/02/2021Service PCompleteR$ 11.176BA
31005617/02/2021Service P-1BasicR$ 10.278BA
31005617/02/2021Service TCompleteR$ 5.932BA
31005617/02/2021Service T-1BasicR$ 5.920BA
31005617/02/2021Service T-2PopularR$ 5.255BA
31005617/02/2021Service T-3SimpleR$ 0BA

 

What I need to do, is to create a graphic (or a table) and show only the Service that have the lowest average price (ignoring the zeroes) per State, and apply in this view filters based on the month or the Service Category. Actually I could calculate the average per product and State using a simple DAX:

 

Average Price = CALCULATE(AVERAGE(FACT_QUOTES[Price]),FACT_QUOTES[Price]>0)
 
In this sample, it actually shows the average for all products per state "AC" in a table, without any filtering:
Sample Average PricesSample Average Prices
 
What I need is to show only "Service L-1" in this scenario. In the same sample, if you filter only the "Complete" in a "Service Category" filter, I need to show only the line with "Service S" and so on for the other states.
I tried using TOPN on view filtering or inside a DAX Formula, RANKX also but it didn't work for me, maybe I'm missing something, so any help is appreciated. Searched for similar posts here but haven't found a similar situation. I don't know how to include a pbix or xlsx file here to include my sample files.
 
Thanks for your help!!
 
1 ACCEPTED SOLUTION
MichelDias
Frequent Visitor

OK, I found the solution and it was easier than I thought, what I did was to create a DAX function to reach only the lowest average using the SUMMARIZE function over the Service context:

IsMinAverage =
VAR MinorPrice = MINX(
SUMMARIZE(ALL(FACT_QUOTES[Service]),
FACT_QUOTES[Service]),
[Average Price]
)
RETURN IF([Average Price]=MinorPrice,1,0)
 
Once I used this, I could include a filter in my result table showing only rows where "IsMinAverage" = 1. Also, where there are no values in the range I needed to include an additional filter for "Average Price" > 0.

View solution in original post

5 REPLIES 5
MichelDias
Frequent Visitor

OK, I found the solution and it was easier than I thought, what I did was to create a DAX function to reach only the lowest average using the SUMMARIZE function over the Service context:

IsMinAverage =
VAR MinorPrice = MINX(
SUMMARIZE(ALL(FACT_QUOTES[Service]),
FACT_QUOTES[Service]),
[Average Price]
)
RETURN IF([Average Price]=MinorPrice,1,0)
 
Once I used this, I could include a filter in my result table showing only rows where "IsMinAverage" = 1. Also, where there are no values in the range I needed to include an additional filter for "Average Price" > 0.
Syk
Super User
Super User

Try the TOPN filter on the visual and choose 'Bottom' 1 based on the Average Price

Thanks @Syk for the quick response, I already tried this but didn't work, when applying the TOPN filter in the visual, it only shows the same product for all States, no matter if there are other lower prices it gets only the one with the lowest average between all the filtered products.

So basically you need the cheapest service per state. (cheapest based on avg price)?

Exactly!

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.