Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Daniela_Romasko
Frequent Visitor

Frequência de compra semanal

Olá, 

 

Estou tentando criar um código para calcular a semana que os clientes compraram.
Usei o DAX: 

Frequencia Compra = DISTINCTCOUNT(TB_FATURAMENTO[N NOTA]) para calcular a frequencia de compra.
Porém preciso de uma fórmula que a cada semana que o cliente comprar acrescente uma compra, independente de quantas vezes ele comprou na semana. 
 
Pode me ajudar?
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Daniela_Romasko  Try like

Purchase Frequency = Countrows(Summarize(TB_FATURAAMENTO, TB_FATURAAMENTO[Year Week], TB_FATURAAMENTO [N NOTE] ) )

View solution in original post

v-yangliu-msft
Community Support
Community Support

Hi  @Daniela_Romasko ,

I created some data:

vyangliumsft_0-1673580518547.png

 

Here are the steps you can follow:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_1-1673580518549.png

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:

vyangliumsft_2-1673580518550.png

 

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

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Daniela_Romasko ,

I created some data:

vyangliumsft_0-1673580518547.png

 

Here are the steps you can follow:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_1-1673580518549.png

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:

vyangliumsft_2-1673580518550.png

 

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

amitchandak
Super User
Super User

@Daniela_Romasko  Try like

Purchase Frequency = Countrows(Summarize(TB_FATURAAMENTO, TB_FATURAAMENTO[Year Week], TB_FATURAAMENTO [N NOTE] ) )

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.