The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi all,
I'm having some trouble with the Dax logic. I have a data set, which I don't have access right now, but the structure is simple:
Data - product ID - product description - brand - paid price
Each observation is a sold product. It is not grouped by quantity.
My objective is to group these events by date and brand, calculate the average price by brand, and also an competiveness index, which I'm struggling to create.
The index reasoning is not a big deal, I want to use a specific brand as a reference and calculate the relativity between the other brands.
For example, I have three brands, (Nike, adidas, puma). Referencing "Nike" as an example, I would like to divide the avg price from Adidas and puma separately, and as a final result understand the relativity between the brands.
Using Dax, I tried doing the following:
"compt:= IF(table[brand] ="Nike", 1, table[price] / Calculate(Average(table[price]), Filter(table, table[brand] = "Nike" "
My objective here was to normalize my reference and then divide each observation, so I could obtain the result for each brand.
The result is not what I expect, usually the result is always "infinite"
Unfortunately I really don't have the data available at this moment, but later I would be able to update the section if needed.
I would appreciate all the help, and tips, since I'm a new user, it is always a challenge.
Thanks!
@amitchandak, thanks for the reply, unfortunately it didn't work.
I could achieve some success by creating a calculated column and applying the formula below:
compt_index = DIVIDE(InfoPrice[PrecoPadrao],
CALCULATE(
AVERAGEX(InfoPrice, InfoPrice[avg_price_brand]),
FILTER(InfoPrice, InfoPrice[Marca] = "Brand1"),
FILTER(InfoPrice, InfoPrice[Data].[Ano] = EARLIER(InfoPrice[Data].[Ano])),
FILTER(InfoPrice, InfoPrice[Data].[Mês] = EARLIER(InfoPrice[Data].[Mês]))
)
)
*[avg_price_brand] is another calculated column that is just the avg price of the whole table.
It works in a scenario that i don't have filters other than data, which i could achieve by using the earlier function.
Year | 2022 | Year | 2023 | |
Avg. Price | Avg. Of Competiveness Index | Avg. Price | Avg. Of Competiveness Index | |
Brand1 | 3,92 | 0,62 | 4,13 | 0,6 |
Brand2 | 4,43 | 0,7 | 4,50 | 0,66 |
Brand3 | 6,11 | 0,97 | 6,11 | 0,89 |
Brand4 | 5,25 | 0,83 | 5,25 | 0,77 |
Brand5 | 6,40 | 1,02 | 6,20 | 0,91 |
Brand6 | 6,31 | 1 | 6,84 | 1 |
However, i have other segmentation filters that the user will be able to choose, for example, "State", "Packing size", "Brand" and/or "Volume".
These addtional filters didn't work in a calculated column by including the same FILTER() formula and assigning the SELECTEDVALUE(InfoPrice[State]) but no success at all.
I also tried to include this formula in a measure, but the earlier function does not fit in it, formula below:
compt_ind_2 =
var preco_ref =
CALCULATE(AVERAGEX(InfoPrice, InfoPrice[price]),
FILTER(InfoPrice, InfoPrice[Marca] = "brand4")
)
var avg_marcas =
VAR flt_uf = SELECTEDVALUE(Aux_UF[DescUF])
VAR flt_emb = SELECTEDVALUE(Aux_Produtos[Pack_size])
VAR flt_vol = SELECTEDVALUE(Aux_Produtos[Volume])
VAR flt_channel = SELECTEDVALUE(Aux_TipoDeLoja[TipoPadrao])
RETURN
CALCULATE(AVERAGEX(InfoPrice, InfoPrice[brand]),
FILTER(InfoPrice, InfoPrice[brand]), InfoPrice[brand],
Aux_UF[DescUF] = flt_uf,
Aux_Produtos[pack_size] = flt_emb,
Aux_Produtos[Volume] = flt_vol,
Aux_TipoDeLoja[TipoPadrao] = flt_channel
)
var compt_ind =
DIVIDE(avg_marcas, preco_ref)
return compt_ind
Any ideas on how to proceed?
Thanks!
João
@jgap98 , Based on what I got measure like
Calculate( calculate(Averagex(Values(Table[Brand]) , calculate(Average(Table[Price]) ) )
, allselected())
or
calculate(
calculate(Averagex(Values(Table[Brand]) , calculate(Average(Table[Price]), filter(Table[Brand] <>Max(Table[Brand] ) )
, allselected())
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
21 | |
19 | |
19 | |
18 | |
14 |
User | Count |
---|---|
42 | |
39 | |
24 | |
21 | |
19 |