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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors