Forum Discussion
Problem getting minomo value by group
You have a table, UltimasEntradas, which is a summary of another table, Entradas, and it's filtered for entries within the last 180 days. This table gives you the product ID, product name, the last date of entry, and the last value without tax for each product.
You're trying to get the minimum value (ultimovalor) for each group (apresentacao). The problem you're facing is that for some products, the minimum value returned is from a product that doesn't belong to any presentation group.
The DAX for Column 1 you provided is trying to get the minimum value for each group and then return the product name (nomeproduto) that has this minimum value.
From what I understand, the issue is that the minimum value is sometimes taken from a product that doesn't belong to any presentation group. To fix this, you should filter out those products without a presentation before calculating the minimum value.
Here's a suggestion to modify your Column 1:
Min_Produto =
VAR MinValue =
CALCULATE(
MINX(UltimasEntradas, UltimasEntradas[UltimoValor]),
ALLEXCEPT(UltimasEntradas, 'apresentaçao'[apresentacao]),
NOT(ISBLANK(UltimasEntradas['apresentaçao'[apresentacao]])) -- This line ensures we only consider products with a presentation
)
RETURN
MINX(
FILTER(UltimasEntradas, UltimasEntradas[UltimoValor] = MinValue),
UltimasEntradas[NomeProduto]
)
The added line ensures that when calculating the minimum value, it only considers products that have a presentation. This should prevent the issue where the minimum value is taken from a product without a presentation.