Olá,
Estou tentando criar um código para calcular a semana que os clientes compraram.
Usei o DAX:
Solved! Go to Solution.
@Daniela_Romasko Try like
Purchase Frequency = Countrows(Summarize(TB_FATURAAMENTO, TB_FATURAAMENTO[Year Week], TB_FATURAAMENTO [N NOTE] ) )
Hi @Daniela_Romasko ,
I created some data:
Here are the steps you can follow:
1. In Power Query -- Add Column – Index Column – From 1.
2. Create calculated column.
Count =
COUNTX(
FILTER(ALL('Table'),
'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Week]=EARLIER('Table'[Week])),[Week number])
Flag =
var _min=
MINX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Week]=EARLIER('Table'[Week])),[Index])
return
IF(
_min=[Index],1,0)
increase+1 =
[Count] +
SUMX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Index]<=EARLIER('Table'[Index])),[Flag])
Week number =
CALCULATE(DISTINCTCOUNT('Table'[Week]),
FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])))
3. Result:
If it doesn't meet your expectations,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you
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
Hi @Daniela_Romasko ,
I created some data:
Here are the steps you can follow:
1. In Power Query -- Add Column – Index Column – From 1.
2. Create calculated column.
Count =
COUNTX(
FILTER(ALL('Table'),
'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Week]=EARLIER('Table'[Week])),[Week number])
Flag =
var _min=
MINX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Week]=EARLIER('Table'[Week])),[Index])
return
IF(
_min=[Index],1,0)
increase+1 =
[Count] +
SUMX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Index]<=EARLIER('Table'[Index])),[Flag])
Week number =
CALCULATE(DISTINCTCOUNT('Table'[Week]),
FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])))
3. Result:
If it doesn't meet your expectations,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you
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
@Daniela_Romasko Try like
Purchase Frequency = Countrows(Summarize(TB_FATURAAMENTO, TB_FATURAAMENTO[Year Week], TB_FATURAAMENTO [N NOTE] ) )