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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Diego_Vialle
Helper II
Helper II

Custom Column in Power Query

I have a measure created in DAX to demonstrate:
Customers who have never purchased, but have purchased within the last two months.


I would like a custom column in Power Query with this rule, it can be a boolean column. Here is the DAX formula used:

 

Frequencia pedidos Bimestral =
VAR AllOldCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS,
SBOPRODMS[Data NF]
< TODAY () - 60,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
VAR AllNewCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS[Data NF]
< TODAY () ,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
RETURN
COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )
8 REPLIES 8
wdx223_Daniel
Community Champion
Community Champion

NewStep=let a=Date.AddDays(DateTime.LocalNow(),-60),b=List.Buffer(List.Accumulate(Table.ToRecords(PrivousStepName),{{},{}},(x,y)=>if y[Documento]="Nota fiscal de saída" and y[Data NF]<a then {List.RemoveItems(x{0},{y[Nome do PN]}),x{1}&{y[Nome do PN]}} else if List.Contains(x{1},y[Nome do PN]) then x else {x{0}&{y[Nome do PN]},x{1}}){0}) in Table.AddColumn(PrivousStepName,"CustomColumn",each List.Contains(b,[Nome do PN]))

I didn't understand what to insert in Previous Step Name:

 

Diego_Vialle_0-1650284801295.png

 

The previous step's name is Columnas Renomeadas2, so you'd use write #"Columnas Renomeadas2" instead of PreviousStepName.

Anonymous
Not applicable

if you explain where you are starting from and what you want to achieve, even those unfamiliar with DAX can look for a solution

I demonstrated the formula in DAX because I thought it would make it easier to understand. But no problem.

I need a column that brings me customers who have never purchased but have purchased in the last two months.

I have the following columns to filter:
[NP Name]
[Invoice Date]
[Document] = "A/R Invoice"

Anonymous
Not applicable

two months purchaser.pngit may be that I, in addition to the DAX, have problems with English. I can't understand what you mean by customers who have never purchased but have purchased in the last couple of months.

 

Se l'intenzione è quella di trovare i clienti che hanno comprato SOLO negli ultimi due mesi ma non hanno comprato mai prima, devi fare un table.group sulla colonna [NP Name], poi controlli se la data minima di ogni gruppo ricade negli ultimi due mesi (vedi l'istruzione sotto.).

Se vuoi lo script completo, posta delle tabelle (anche fittizie) con i dati minimi che serveno per trattare tutte le casistiche che ti ritrovi in relatà.

 

Date.IsInPreviousNMonths([invoicedate],2))

 

 

Sì, l'intenzione è spiegata da te. Avere una colonna booleana (vero o falso), che ti dice quali clienti NON hanno MAI acquistato, MA acquistato negli ultimi 2 mesi. Di seguito è riportato l'esempio.

 

Diego_Vialle_0-1650198718687.png

Avevo creato questa misura in DAX, ma sto riscontrando un problema con i filtri di report che stanno portando TUTTI i client:

 

Diego_Vialle_2-1650199567153.png

 

Diego_Vialle_3-1650199586124.png

 

Novos Clientes Bimestrais =
VAR AllOldCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS,
SBOPRODMS[Data NF]
< TODAY () - 60,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
VAR AllNewCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS[Data NF]
< TODAY () ,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
RETURN
COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )

 

Anonymous
Not applicable

se carichi qui (o da qualche parte accessibile) delle tabelle  facili da copiare su cui lavorare, posso provare a scrivere il codice che cerchi.

 

 

Helpful resources

Announcements
December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.